System.out.print("* ");
}
System.out.println();
}
}
10、计算器程序
public class Calculator {
private int index;
public void add(int i,int j){
System.out.printf("%d+%d=%d",i,j,i+j);
}
public void sub(int i,int j){
System.out.println(i-j);
}
public void mul(int i,int j){
System.out.println(i*j);
}
public void div(int i,int j){
System.out.println(i/j);
}
public void mod(int i,int j){
System.out.println(i%j);
}
public String getInput(){
Scanner in=new Scanner(System.in);
return in.nextLine();
}
public static void main(String[] args){
Calculator calculator=new Calculator();
while(1==1){
System.out.println("请输入表达式:如a+-*/b");
String input=calculator.getInput();
calculator.operate(input);
}
}
private void operate(String input) {
index=-1;