signqmar signqmar - 13 days ago 7
Java Question

Error: Could not find or load main class calculator.Calculator /home/kubuntu/.cache/netbeans/8.2/executor-snippets/run.xml:53

My complete code:

import java.util.*;

public class Calculator {

public static void main(String[] args) {

double n1, n2;
String operation;

Scanner scan = new Scanner(System.in);

System.out.println("Enter the first number: ");
n1 = scan.nextDouble();

System.out.println("Enter second number: ");
n2 = scan.nextDouble();

Scanner op = new Scanner(System.in);
System.out.println("Enter +,-,/: ");
operation = op.next();

switch (operation) {
case "+":
System.out.println("Your answer is " + (n1 + n2));
break;

case "-":
System.out.println("Your answer is " + (n1 - n2));
break;

case "/":
System.out.println("Your answer is " + (n1 / n2));
break;

case "*":
System.out.println("Your answer is " + (n1 * n2));
break;

default:
System.out.println("You are finished");
}
}
}


I am currently trying to create a calculator.
If anyone is ABLE to help, it would be much appreciated.
(if you could also that add simple comments that would be great too)

Answer

You are missing one operator :)

Scanner scan = new Scanner(System.in);

And it works fine for me then.