Answer to Question #3521 in Java | JSP | JSF for Y mukundareddy
2011-07-13T16:41:47-04:00
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.
1
2012-03-06T10:39:53-0500
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 !
Learn more about our help with Assignments:
Java JSP JSF
Comments
Leave a comment