Hey guys working on a simple switch program but not exactly a 100% if i can convert my what was a if statement into a switch or not. Any help would be awesome Thanks!
import java.util.Scanner; public class math { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println(" Please select one of these options."); System.out.println(" 1. Press A to add three numbers "); System.out.println(" 2. Press S to subtract two numbers "); System.out.println(" 3. Press M to multiply by three numbers "); System.out.println(" 4. Press D to divide by two numbers "); System.out.println(" 5. Press O to modulus two numbers "); System.out.println(" 6. Press E to quit the program "); System.out.println(" "); int option= input.nextInt(); switch (option) { case 'A': { addition (); } break; case 'S': { subtract (); } break; case 'M': { multiply (); } break; case 'D': { divide (); } break; case 'O': { modulus (); } break; case 'E': { quit ();} break; default: System.out.println("Not a option"); } } public static void addition(){ Scanner input = new Scanner( System.in ); float number1; float number2; float number3; float sum; System.out.printf( "Enter first integer: " ); number1 = input.nextInt(); System.out.printf( "Enter second integer: " ); number2 = input.nextInt(); System.out.printf( "Enter Third integer: " ); number3 = input.nextInt(); sum = number1 + number2 + number3; System.out.printf( "Sum equals %f\n", sum); } public static void subtract(){ Scanner input = new Scanner( System.in ); float number1; float number2; float difference; System.out.printf( "Enter number to be subtracted: " ); number1 = input.nextInt(); System.out.printf( "Enter integer to subtract: " ); number2 = input.nextInt(); difference = number1 - number2; System.out.printf( "The difference is %f\n", difference); } public static void multiply(){ Scanner input = new Scanner( System.in ); float number1; float number2; float number3; float product; System.out.printf( "Enter first integer to multiply: " ); number1 = input.nextInt(); System.out.printf( "Enter second integer: " ); number2 = input.nextInt(); System.out.printf( "Enter Third integer: " ); number3 = input.nextInt(); product = number1 * number2 * number3; System.out.printf( "The product is %f\n", product); } public static void divide(){ Scanner input = new Scanner( System.in ); float number1; float number2; float dividen; System.out.printf( "Enter first integer: " ); number1 = input.nextInt(); System.out.printf( "Enter second integer: " ); number2 = input.nextInt(); dividen = number1 / number2; System.out.printf( "The dividen equals %f\n", dividen); } public static void modulus(){ Scanner input = new Scanner ( System.in ); float number1; float number2; float sum; System.out.printf( "Enter first integer: " ); number1 = input.nextInt(); System.out.printf( "Enter second ineger: " ); number2 = input.nextInt(); sum = number1 % number2; System.out.printf( "The answer equals %f\n", sum); } public static void quit(){ System.out.printf( "Thank you for trying to use the program."); return; } }