Import Java.util.Scanner;
public class Calculator {
public static void Main (string[] args) {
System.out.println ("operator is +,-,*,/");
Scanner sc = new Scanner (system.in);
System.out.println ("Please enter the first number:");
String aStr = Sc.nextline ();
System.out.println ("Please enter a second number:");
String bStr = Sc.nextline ();
System.out.println ("Please enter operator:");
String cc = Sc.nextline ();
Double A = double.parsedouble (ASTR);
Double b = double.valueof (BSTR);
Core Core = new core ();
Core.calc (CC, A, b);
}
}
public class Core {
public void Calc (String cc, double A, double b) {
if (cc.equals ("+")) {
System.out.println (A + B);
} else if (Cc.equals ("-")) {
System.out.println (A-B);
} else if (Cc.equals ("*")) {
System.out.println (A * b);
} else if (Cc.equals ("/")) {
if (b! = 0) {
System.out.println (A/b);
} else {
SYSTEM.OUT.PRINTLN ("Denominator cannot be zero!") ");
}
} else {
SYSTEM.OUT.PRINTLN ("Input does not meet the requirements!") ");
}
}
}
Knot pair Classmate: Mo Junyu http://www.cnblogs.com/mjysok/
Arithmetic Testing and encapsulation