In: Computer Science
import java.util.Scanner;
class Even_Odd{
public static void main(String[] args){
int num;
Scanner in = new Scanner(System.in);
System.out.print("Enter a number to check: ");
num = in.nextInt();
if(num % 2 == 0){
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}
import java.util.Scanner;
class User{
public static void main(String[] args){
int password;
String username;
Scanner in = new Scanner(System.in);
//get username from user
System.out.print("Enter your username: ");
username = in.next();
//get password from user
System.out.print("Enter your password: ");
password = in.nextInt();
//if username is Ahmed and password is 2321
if(username.equals("Ahmed") && password==2321){
System.out.println("Hi ..Welcome to my program");
}
//if username is Ali and password is 6776
else if(username.equals("Ali") && password==6776){
System.out.println("Hi ..Welcome to my program");
} //if username and password are not recognized
else {
System.out.println("Sorry!! I don’t recognize you");
}
in.close();
}
}
import java.util.Scanner;
class Gpa {
public static void main(String[] args){
float gpa;
Scanner in = new Scanner(System.in);
System.out.print("Enter gpa: ");
gpa = in.nextFloat();
// Gpa > 3.90
if(gpa >= 3.90){
System.out.println("Excellent .. you are at First honor");
} // Gpa > 3.70
else if(gpa >= 3.70){
System.out.println("Excellent .. you are at Second honor");
} // Gpa > 3.5
else if(gpa >= 3.50){
System.out.println("Excellent .. you are at Third honor");
} //Gpa < 3.50 and > 2.00
else if(gpa < 3.50 && gpa >= 2.00){
System.out.println("Good .. Work hard to raise your GPA");
} // Otherwise
else {
System.out.println("WORK HARD … You are in trouble");
}
in.close();
}
}
Thank You...!