Switch case in Java
import java.util.*;
class switch1
{
public static void main(String args[])
{
int ch,a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("1.Addition \n 2.Substraction \n 3.Multiplication\n 4.Division \n5.Modation");
System.out.println("Enter your choice");
ch=sc.nextInt();
System.out.println("Enter the two no");
a=sc.nextInt();
b=sc.nextInt();
switch(ch)
{
case 1:
c=a+b;
System.out.println("Sum="+c);
break;
case 2:
c=a-b;
System.out.println("Sub="+c);
break;
case 3:
c=a*b;
System.out.println("multi="+c);
break;
case 4:
c=a/b;
System.out.println("divis="+c);
break;
case 5:
c=a%b;
System.out.println("modation="+c);
break;
default:
System.out.println("Wrong choice");
break;
}
}
}
output:
1.Addition
2.Substraction
3.Multiplication
4.Division
5.Modation
Enter your choice
1
Enter the two no
2
3
Sum=5
class switch1
{
public static void main(String args[])
{
int ch,a,b,c;
Scanner sc=new Scanner(System.in);
System.out.println("1.Addition \n 2.Substraction \n 3.Multiplication\n 4.Division \n5.Modation");
System.out.println("Enter your choice");
ch=sc.nextInt();
System.out.println("Enter the two no");
a=sc.nextInt();
b=sc.nextInt();
switch(ch)
{
case 1:
c=a+b;
System.out.println("Sum="+c);
break;
case 2:
c=a-b;
System.out.println("Sub="+c);
break;
case 3:
c=a*b;
System.out.println("multi="+c);
break;
case 4:
c=a/b;
System.out.println("divis="+c);
break;
case 5:
c=a%b;
System.out.println("modation="+c);
break;
default:
System.out.println("Wrong choice");
break;
}
}
}
output:
1.Addition
2.Substraction
3.Multiplication
4.Division
5.Modation
Enter your choice
1
Enter the two no
2
3
Sum=5
Comments
Post a Comment