63 132
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #3521 in Java | JSP | JSF for Y mukundareddy

Question #3521
3) Write a program using switch and break separately to print the desired output when you give an input as 1 to add, 2 to multiply, 3 to subtract.
Expert's answer
import java.util.Scanner;




public class Question1 {




/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner in = new Scanner(System.in);



System.out.println("Write to numbers");

int x1 = in.nextInt();

int x2 = in.nextInt();

int result = 0;

System.out.println("Write number of action");

int action = in.nextInt();



switch(action){

case 1:

result = x1+x2;

break;

case 2:

result = x1*x2;

break;

case 3:

result = x1-x2;

break;

}



System.out.println(result);

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions