3 回答
TA贡献2039条经验 获得超7个赞
您可以打印每个menuOption方法的结果
public static double menuOption2() {
System.out.println("Enter the amount of kilometers you wish to convert: ");
double km = keyBd.nextDouble();
double miles = 0.621371 *km;
System.out.println(String.format("%s", miles));
return miles;
}
或从案例陈述
switch(selection) {
case '1':
double result = menuOption1();
System.out.println(String.format("%s", result));
break;
case '2':
double result = menuOption2();
System.out.println(String.format("%s", result));
break;
case '3': break;
default: System.out.println("Invalid selection!");
}
TA贡献1811条经验 获得超4个赞
case '1': System.out.println("Result "+menuOption1()); break;
case '2': System.out.println("Result "+menuOption2()); break;
case '3': break;
default: System.out.println("Invalid selection!");
TA贡献1877条经验 获得超1个赞
您可以像这样在 de Switch 中打印结果,我还添加了一个新行,请求一个参数。
switch(selection) {
case '1': {
System.out.println("Fill Kgs to be converted");
System.out.println("Result of converting KG to Lbs is : " + menuOption1());
break;
}
case '2': {
System.out.println("Fill Kilometers to be converted");
System.out.println("Result of converting Kms to Miles is : " + menuOption2());
break;
}
case '3': break;
default: System.out.println("Invalid selection!");
}//end switch
添加回答
举报