my parnter code review
import java.util.Scanner; public class Test { static boolean flag = false; /** * 获取输入数字 * @return */ public static double dataInput(){ double stmp = 0; flag = false; try { Scanner sc = new Scanner(System.in); stmp = sc.nextDouble(); } catch (Exception e) { flag = true; System.out.println("输入数据类型错误!请重新输入!"); stmp = 0; } return stmp; } /** * 运算方法 * @param d1 * @param d2 * @return */ public static double division(double d1,double d2){ double temp = 0; flag = false; try { temp = d1/d2; } catch (Exception e) { flag = true; System.out.println("除数不能为0"); temp = 0; } return temp; } public static void main(String[] args) { double d1 = 0; double d2 = 0; while(true){ System.out.println("----------开始-----------"); do{ System.out.print("请输入除数:"); d1 = dataInput(); }while(flag); do{ System.out.print("请输入被除数:"); d2 = dataInput(); }while(flag); System.out.println("运算结果为:"+division(d1, d2)); } } }
1.格式不标准
2.注释不够详细具体
1.输入的时候,不知道输入的是否数字呢,怎么能用 sc.nextDouble()来获取浮点数呢?
2.判断数字的正则表达式好像有点问题