Problem 15:
Write a program that
take number from user and check number is less then five 0r lessthen 10 simply
using switch statement
Discripition:
Case 1 2 3 4 for less
then five and 5 6 7 8 9 less then ten
Solution:
import java.util.*;
public class Message {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number:
");
int i= input.nextInt();
switch(i) {
case 0:
case 1:
case 2:
case 3:
case 4:
System.out.println("i is
less than 5");
break;
case 5:
case 6:
case 7:
case 8:
case 9:
System.out.println("i is
less than 10");
break;
default:
System.out.println("i is
10 or more");}
}
}
Output:
No comments:
Post a Comment