Skip to content

Commit f44bc93

Browse files
Added menu driven switch case
1 parent 191b634 commit f44bc93

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

switchcase.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#https://www.facebook.com/lakshay.gulati.5/posts/3439658002768650
2+
#subscribed by Lakshay
3+
4+
public class switchcase {
5+
6+
public static void main(String[] args) {
7+
8+
System.out.println("Choose an option:-");
9+
System.out.println("1.To check if the no. is composite");
10+
System.out.println("2.To find the smallest digit");
11+
Scanner scan = new Scanner(System.in);
12+
int choice = scan.nextInt();
13+
int store[];
14+
15+
switch(choice){
16+
case 1:
17+
{
18+
System.out.println("Enter the number");
19+
int num = scan.nextInt();
20+
for (int i = 2;i<num;i++){
21+
if((num%i)==0){
22+
System.out.println("The number is Composite");
23+
break;}
24+
if(i==(num-1)){
25+
System.out.println("The number is prime");
26+
}
27+
else{
28+
continue;}
29+
}
30+
}break;
31+
case 2:
32+
{
33+
System.out.println("Enter the number");
34+
String num1 = scan.next();
35+
store= new int[num1.length()];
36+
int num = Integer.parseInt(num1);
37+
38+
for (int j = 0;j>=0;j++){
39+
if(num==0){
40+
break;}
41+
store[j]=(num%10);
42+
num=num/10;
43+
44+
}
45+
Arrays.sort(store);
46+
System.out.println(store[0]);
47+
}break;
48+
default:{
49+
System.out.println("Enter the Correct choice");}break;
50+
}
51+
52+
53+
54+
55+
}
56+
}

0 commit comments

Comments
 (0)