package com.boke; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner s = new Scanner(System.in); do { System.out.println("您已进入简单计算器 如需退出请按Z/重算请按H"); //进入第一个数字并判断是否为z/h System.out.println("请输入第一个数字 "); String num1 = s.next(); if(num1.equals("z")){ System.out.println("已退出简单计算"); return; }else if(num1.equals("h")){ System.out.println("重新开始运算"); continue; } //进入第二个符号并判断是否为z/h System.out.println("请输入符号 "); String symbol =s.next(); if(symbol.equals("z")){ System.out.println("已退出简单计算"); return; }else if(symbol.equals("h")){ System.out.println("重新开始运算"); continue; } //进入第三个数字并判断是否为z/h System.out.println("请输入第二个数字 "); String num2 = s.next(); if(num2.equals("z")){ System.out.println("已退出简单计算"); return; }else if(num2.equals("h")){ System.out.println("重新开始运算"); continue; } if(symbol.equals("+")){ System.out.println(num1 + symbol + num2 + " = " + (Integer.parseInt(num1)+Integer.parseInt(num2))); }else if(symbol.equals("-")){ System.out.println(num1 + symbol + num2 + " = " + (Integer.parseInt(num1)-Integer.parseInt(num2))); } else if (symbol.equals("*")){ System.out.println( num1 + symbol + num2 + " = " + (Integer.parseInt(num1)*Integer.parseInt(num2))); }else if(symbol.equals("/")){ System.out.println( num1+ symbol + num2 + " = " + (Integer.parseInt(num1)/Integer.parseInt(num2))); }else { System.out.println("您输入的符号不对!!!不能进行运算,请重新输入"); continue; } }while (true); } }