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");
}
}