I am trying to create a calculator for class, we have to show the operation, we have to make it loop back to the top where it says to enter the first number but also give an option to return back to the top every time I try to add something, something goes wrong any ideas on how to make this calculator on how I want it to be?
import java.util.Scanner;
public class Calculator {
public static void main(String[] argument) {
{
char repeat; //initialize repeat
String input; //initialize input
Scanner keyboard = new Scanner(System.in);
System.out.println(" Please enter the first Number");
int Number1 = keyboard.nextInt();
System.out.println("Please enter the second number");
int Number2 = keyboard.nextInt();
System.out.println("Please enter the operation");
keyboard.nextLine();
{
System.out.println(
"The result of " + Number1 + " + " + Number2 + " = " + (Number1 + Number2));
System.out.println(
"The result of " + Number1 + " - " + Number2 + " = " + (Number1 - Number2));
System.out.println(
"The result of " + Number1 + " * " + Number2 + " = " + (Number1 * Number2));
System.out.println(
"The result of " + Number1 + " % " + Number2 + " = " + (Number1 % Number2));
System.out.println(
"The result of " + Number1 + " / " + Number2 + " = " + (Number1 / Number2));
if (Number2 >= 0) System.out.println("Division by Zero is not possible.");
System.out.println("Please run program again and ");
System.out.println("enter a number other then zero.");
}
String userChoice = null;
do {
System.out.println("Would you like to " + "select again? ");
System.out.print("Enter Y for yes or N for no: ");
input = keyboard.nextLine();
repeat = input.charAt(0);
} while (repeat == 'Y' || repeat == 'y');
System.out.println(userChoice); //give user option to go back to the top
{
keyboard.close();
}
}
}
}