Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String operation;
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- // Ask user how many numbers he/she wants to use
- System.out.print("How many numbers are you using? (3 numbers maximum) ");
- int numberFirst = in.nextInt();
- if (numberFirst > 3) {
- System.out.println("You can't do that. Please start over.");
- System.out.close();
- }
- if (numberFirst < 2) {
- System.out.println("You can't do that. Please start over.");
- System.out.close();
- }
- // Ask user to type in numbers
- System.out.println("Enter first number used: ");
- double num1 = in.nextDouble();
- System.out.println("Enter second number used: ");
- double num2 = in.nextDouble();
- if (numberFirst == 2)
- System.out.println("Press '0' and press 'enter.'");
- if (numberFirst == 3) {
- System.out.println("Enter third number used: ");
- }
- double num3 = in.nextDouble();
- // Output numbers user entered
- if (numberFirst == 2) {
- System.out.println("You are using " + num1 + " and " + num2 + ".");
- }
- if (numberFirst == 3) {
- System.out.println("You are using " + num1 + ", " + num2 + ", and " + num3 + ".");
- }
- // Put a key for the operations
- System.out.println("Addition: Enter '1'");
- System.out.println("Subtraction: Enter '2'");
- System.out.println("Multiplication: Enter '3'");
- System.out.println("Division: Enter '4'");
- if (numberFirst == 2) {
- System.out.println("Exponent: Enter '5'");
- }
- // Ask user what operation he/she wants
- System.out.println("Enter operation: ");
- operation = in.next();
- // Print the operation that user is using AND print the answer (2 numbers)
- if (numberFirst == 2) {
- if (operation.equals("1"))
- System.out.println("You are using addition." + " Your answer is " + (num1 + num2) + ".");
- }
- if (numberFirst == 2) {
- if (operation.equals("2"))
- System.out.println("You are using subtraction." + " Your answer is " + (num1 - num2) + ".");
- }
- if (numberFirst == 2) {
- if (operation.equals("3"))
- System.out.println("You are using multiplication." + " Your answer is " + (num1 * num2) + ".");
- }
- if (numberFirst == 2) {
- if (operation.equals("4"))
- System.out.println("You are using division." + " Your answer is " + (num1 / num2) + ".");
- }
- if (numberFirst == 2) {
- if (operation.equals("5"))
- System.out.println("You are using an exponent." + " Your answer is " + Math.pow(num1, num2) + ".");
- }
- // Print the operation that user is using AND print the answer (3 numbers)
- if (numberFirst == 3) {
- if (operation.equals("1"))
- System.out.println("You are using addition." + " Your answer is " + (num1 + num2 + num3) + ".");
- }
- if (numberFirst == 3) {
- if (operation.equals("2"))
- System.out.println("You are using subtraction." + " Your answer is " + (num1 - num2 - num3) + ".");
- }
- if (numberFirst == 3) {
- if (operation.equals("3"))
- System.out.println("You are using multiplication." + " Your answer is " + (num1 * num2 * num3) + ".");
- }
- if (numberFirst == 3) {
- if (operation.equals("4"))
- System.out.println("You are using division." + " Your answer is " + ((num1 / num2) / num3) + ".");
Add Comment
Please, Sign In to add comment