<分区>
下面是代码,当我除以 5/6 时,它显示 0.0 输出而不是 0.8333。
package sunday;
import java.util.Scanner;
public class exception {
public static void main(String[] args) {
int donut,milk;
double donutperglass;
Scanner in=new Scanner(System.in);
try{
System.out.println("enter donut");
donut=in.nextInt();
System.out.println("enter milk");
milk=in.nextInt();
if(milk<1)
throw new Exception("no milk");
donutperglass=donut/milk;
System.out.println(donutperglass);
}catch(Exception e){
System.out.println(e.getMessage());
System.out.println("go buy some milk");
}
System.out.println("end");
// TODO Auto-generated method stub
}
}