GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java-Programs/Basic-Java/AlgrebraicOperationsSwitchCase.java at master · iamarav/Java-Programs Expand file tree/ Copy pathAlgrebraicOperationsSwitchCase.javaMore file actions 59 lines (48 loc) · 1.36 KB / Copy pathAlgrebraicOperationsSwitchCase.javaFile metadata and controls59 lines (48 loc) · 1.36 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 import java.util.Scanner; public class AlgrebraicOperationsSwitchCase { public static void main(String args[]) { //Declaring variables double n1,n2,res = 0; System.out.println("Algebraic Operations of two Numbers with Switch Case Loop\n---"); Scanner scanner = new Scanner(System.in); System.out.println("Enter the number 1: "); n1 = scanner.nextDouble(); System.out.println("Enter the number 2: "); n2 = scanner.nextDouble(); System.out.println("---\nEnter 1 for addition or\n2 for subtraction or\n3 for multiplication or\n4 for division"); int operator = scanner.nextInt(); //Solving by switch case loop for simpler code. switch(operator) { case 1: res = n1+n2; break; case 2: res = n1-n2; break; case 3: res = n1*n2; break; case 4: res = n1/n2; break; default: System.out.println("You have chosen a wrong option.\nPlease choose from the above given options."); end(); } System.out.println(res); end(); scanner.close(); } static void end() { System.out.println("---\nEnter Y to continue or any key to exit!"); Scanner getEndOption= new Scanner(System.in); String option = getEndOption.next(); if(option.equalsIgnoreCase("Y")) { main(null); } else { System.out.println("The Program has ended. Please run the program again."); } getEndOption.close(); } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |