Create a class “StudentName” with a main function. Take a variable of integer data type from user and store its value into variable name “rollno”. Print the name of specific student using switch statements.
Hint: Use 4 different cases and one default. The value of cases should be
Case 10
Case 11
Case 12
Case 13
import java.util.Scanner;
public class StudentName
{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter an interger: ");
int rollno=input.nextInt();
switch(rollno){
case 10:
System.out.println("Student's name is Bob");
break;
case 11:
System.out.println("Student's name is Ruth");
break;
case 12:
System.out.println("Student's name is Hassan");
break;
default:
System.out.println("Invalid");
}
}
}
Comments
Leave a comment