如何编写JAVA计算器小程序
1个回答
展开全部
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String str = br.readLine();
String str1 = br.readLine();
String str2 = br.readLine();
int num1 = Integer.parseInt(str);
int num2=Integer.parseInt(str2);
if(str1.equals("*")){
System.out.println(num1*num2);
}
if(str1.equals("+")){
System.out.println(num1+num2);
}
if(str1.equals("-")){
System.out.println(num1-num2);
}
if(str1.equals("/")){
System.out.println(num1/num2);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
String str = br.readLine();
String str1 = br.readLine();
String str2 = br.readLine();
int num1 = Integer.parseInt(str);
int num2=Integer.parseInt(str2);
if(str1.equals("*")){
System.out.println(num1*num2);
}
if(str1.equals("+")){
System.out.println(num1+num2);
}
if(str1.equals("-")){
System.out.println(num1-num2);
}
if(str1.equals("/")){
System.out.println(num1/num2);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询