成功写出了一个简易计算器,哈哈哈,虽然很low,功能也不完善,但是我感觉自己有一点点进步,哈哈
package com.Rykwert.method; import java.util.Scanner; public class Counter { //计算器,实现加减乘除,并且能够循环接收新数据 /* 写4个方法:加减乘除 利用循环 + switch进行用户交互 传递需要操作的两个数 输出结果 */ public static void main(String[] args) { Scanner operator = new Scanner(System.in); Scanner num1 = new Scanner(System.in); Scanner num2 = new Scanner(System.in); for (int i = 0 ; i <= 2 ; i++){ System.out.println("请输入第一个数据:"); Double m = num1.nextDouble(); System.out.println("请输入运算符:"); String str = operator.next(); System.out.println("请输入第二个数据:"); Double n = num2.nextDouble(); System.out.println("您的输入为:" + m + str + n + "=" ); switch(str){ case "+" : plus(m,n); System.out.println("加法结果为" + plus(m,n)); break; case "-" : decrease(m,n); System.out.println("减法结果为" + decrease(m,n)); break; case "*" : mult(m,n); System.out.println("乘法结果为" + mult(m,n)); break; case "/" : divide(m,n); System.out.println("除法结果为" + divide(m,n)); break; default : System.out.println("您输入的数据不合法!"); break; } } num1.close(); operator.close(); num2.close(); } //加法 public static double plus(double a,double b){ double result = a+b; return result; } //减法 public static double decrease(double a,double b){ double result = a-b; return result; } //乘法 public static double mult(double a,double b){ double result = a*b; return result; } //除法 public static double divide(double a,double b){ double result = a/b; return result; } }