0% found this document useful (0 votes)
27 views

Accept A Number and Check Whether The Number Is Even or Odd

Uploaded by

PRINCE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Accept A Number and Check Whether The Number Is Even or Odd

Uploaded by

PRINCE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Accept name and age and display whether the person is eligible to caste vote
or not.
import java.util.*;
public class q2
{
public static void main(String args[])
{
String name;
int age;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the name : ");
name=sc.nextLine();
System.out.println("Enter age");
age=sc.nextInt();
if(age>=18)
System.out.println(name+" is elligible to caste vote");
else
System.out.println(name+" is not elligible to caste vote");
}
}

2. Accept a number and check whether the number is even or odd.


import java.util.*;
public class q3
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int num;
System.out.println("Enter number: ");
num=sc.nextInt();
if(num%2==0)
System.out.println(num+ "is even");
else
System.out.println(num+" is odd");
}
}

3. Accept 3 angles and check whether they are of triangle or not.


import java.util.*;
public class q4
{
public static void main(String args[])
{
int a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("Enter value of a : ");
a=sc.nextInt();
System.out.println("Enter value of b : ");
b=sc.nextInt();
System.out.println("Enter value of c : ");
c=sc.nextInt();
if((a+b+c)==180)
System.out.println("Angles are of a triangle");
else
System.out.println("Angles are not of a triangle");
}
}

You might also like