Java program
1. Write a program to 'Geet' a person if entered hour is more than 18 then wish "Good evening" otherwise "Have a nice day"
package all;
import java.util.Scanner;
//Greeting a person
public class greeting {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter Hour: ");
int hr=sc.nextInt();
if(hr>18)
System.out.println("Good Evening !!!");
else
System.out.println("Have a nice day!!!");
}
}
2) Write a program to check candidate is eligible for vote or not.
package all;
import java.util.Scanner;
//voiting
public class vote_eligible {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter your Age: ");
int age=sc.nextInt();
if(age>18)
System.out.println("Eligible for vote!!!");
else
{
int elg=18-age;
System.out.println("You are Eligible after "+elg+" Years");
} } }
3) Write a program to check whether given number is positive or negative or zero.
package all;
import java.util.Scanner;
//checking number +,-,0
public class check_number {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter any number ");
int n=sc.nextInt();
if(n>0)
System.out.println("Positive number!!!");
else if (n<0)
System.out.println("Negative number");
else
System.out.println("Given number is zero");
}
}
4) Write a program to check grades of a student using their marks.
package all;
import java.util.Scanner;
//Student grade
public class grade {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter your marks: ");
int m=sc.nextInt();
if(m<50)
System.out.println("Fail");
else if (m>=50&&m<60)
System.out.println("D grade");
else if (m>=60&&m<70)
System.out.println("C grade");
else if (m>=70&&m<80)
System.out.println("B grade");
else if (m>=80&&m<90)
System.out.println("A grade");
else if (m>=90&&m<=100)
System.out.println("O grade");
}
}
5) Write a program to find biggest among 3 numbers.
package all;
import java.util.Scanner;
//Biggest of 3 numbers
public class Biggest_number {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter your 3 numbers:");
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if(a>b&&a>c)
System.out.println("A is greater");
else if (b>a&&b>c)
System.out.println("B is greater");
else
System.out.println("C greater");
}
}
6) Write a program to find whether given year is leap year or not.
package all;
import java.util.Scanner;
//leap year
public class leap_year {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter year: ");
int yr=sc.nextInt();
if(yr%4==0)
System.out.println("Leap year!!!");
else
System.out.println("Not a leap year!!!");
}
}
Note: I am not responsible if any program is wrong, so write at your own risk.
0 Comments