User Interaction (Getting Users' Input)


Source: TestUserInput.java


import java.util.Scanner;

public class TestUserInput {


public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter your Name : ");
String name = scan.next();

System.out.println("Enter your marks : ");
int marks = scan.nextInt();

if (marks > 90) {
System.out.println("Hi " + name + " You got A");
} else if (marks > 70) {
System.out.println("Hi " + name + " You got B");
} else if (marks > 50) {
System.out.println("Hi " + name + " You got C");
} else {
System.out.println("Sorry Dude better luck next time");
}
}
}



No comments :

Post a Comment