0
我無法弄清楚我在這裏做錯了什麼;是你可以用「//」部分看到,我已經嘗試了不同的方式:錯誤消息:java.lang.ArithmeticException:/在survey.results處爲零(survey.java:51)
public class survey {
// instance variables - replace the example below with your own
private double total = 12467;
// private double percentage = 100;
private double one = total * .14; // percentage;
private double citrus = total * .64; // percentage;
public void results(int total) {
System.out.println("Number of people surveyed:" + total);
System.out.println("Number who purchase one or more energy drinks:"
+ one);
System.out.println("Number who prefer citrus flavored energy drinks:"
+ citrus);
}
}
這是我落得這樣做,解決了這個錯誤。感謝大家的及時回覆!
/**
* Write a description of class survey here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class survey
{
// instance variables - replace the example below with your own
private double total = 12467;
private double one = 14 ;
private double citrus = 64 ;
private int oneperc;
private int citrusperc;
{
oneperc = (int) ((total*one/100));
}
{
citrusperc = (int) ((total*citrus/100));
}
public void results(int total)
{
System.out.println("Number of people surveyed:" + total);
System.out.println("Number who purchase one or more energy drinks:" + oneperc);
System.out.println("Number who prefer citrus flavored energy drinks:" + citrusperc);
}
}
修復了您的標籤Java!= Javascript – Barmar
哪一條語句是第51行?爲什麼參數是一個'int'? –
我沒有看到你在哪裏劃分任何東西。 – rgettman