Java Switch Statement with User Input

Java Switch Statement with User Input

Java Switch Statement with User Input


java switch statement with user input,switch case in java example programs with user input,selection statements in java,java switch case string,how to use switch in java



Switch with input in Java Program

import java.io.*;
class arun
{
public Static void main(String args[]) throws IOException
{
DataInputStream in = new DataInputStream(System.in);
{
int a;
System.out.println("Enter the value of a is:");
a=Integer.parseInt(in.readLine());
switch(a)
{
case 1:
{
int b,c,d;
System.out.println("Enter the value of b and c is:");
b=Integer.parseInt(in.readLine());
c=Integer.parseInt(in.readLine());
d=b+c;
System.out.println("The value of d is:"+d);
break;
}
case 2:
{
int b,c,d;
System.out.println("The enter value of b and c is:");
b=Integer.parseInt(in.readLine());
c=Integer.parseInt(in.readLine());
d=b-c;
System.out.println("The value of d is:"+d);
break;
}
case 3:
{
int b,c,d;
System.out.println("Enter the value of b and c is:");
b=Integer.parseInt(in.readLine());
c=Integer.parseInt(in.readLine());
d=b*c;
break;
System.out.println("The value of d is:"+d);
}
case 4:
{
int b,c,d;
System.out.println("Enter the value of b and c is");
b=Integer.parseInt(in.readLine());
c=Integer.parseInt(in.readLine());
d=b/c;
break;
System.out.println("The value of d is:"+d);
}
default:
{
System.out.println("You entered the wrong number");
break;
}
}
}
}
}

Post a Comment

0 Comments