Hello community ^_^
I'm fairly new to the Java language and programming so bare with me on this one. I'm teaching myself and I'm using every resource I can to get better.
I'm currently learning about methods and I got a little creative.
I've created a simple calculator program implementing the use of methods (I'm not sure whether this is the correct way, but I'm doing it anyway)
There are two problems I'm having with the code:
1. It's not letting the user input Yes or No when the it gets to "input = nextLine();". Instead, it skips over this and ends the program.
2. I'm not sure what to put in the if statement or in general to have the code loop back to the beginning of the program and start over instead of having to run the program over again.
I appreciate all the help I can get.
Thanks
static int number; static String passing, input; static int numOne, numTwo, numThree; static Scanner sc = new Scanner(System.in); public static void main(String[] args) { System.out.println("Input first number"); numOne = sc.nextInt(); System.out.println("Input second number"); numTwo = sc.nextInt(); System.out.println("What would you like to do with these numbers?"); System.out.println("1. Addition " + "2. Subtraction " + "3. Multiplication " + "4. Division"); System.out.print(" Enter number: "); anotherOption(); System.out.println(Recieving()); System.out.println("Yes/No"); input = sc.nextLine(); if(input.equals("Yes")){ // back to the beginning } else if(input.equals("No")){ System.exit(0); } } public static void anotherOption() { number = sc.nextInt(); switch(number) { case 1: System.out.println(numOne + numTwo); break; case 2: System.out.println(numOne - numTwo); break; case 3: System.out.println(numOne * numTwo); break; case 4: System.out.println(numOne / numTwo); break; default: System.out.println("Invalid input"); break; } passing = "Would you like to do anything else?"; } public static String Recieving(){ return passing; } }