首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误消息: java.lang.ArithmeticException: /在survey.results(survey.java:51)处为零

错误消息: java.lang.ArithmeticException: /在survey.results(survey.java:51)处为零
EN

Stack Overflow用户
提问于 2013-07-01 23:52:21
回答 1查看 379关注 0票数 0

你可以从"//“部分看出我做错了什么,我尝试过不同的方法:

代码语言:javascript
复制
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);
    }
}

这就是我最后所做的,解决了错误。感谢大家的及时回复!

代码语言:javascript
复制
/**
 * 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);
        }
}
EN

回答 1

Stack Overflow用户

发布于 2013-07-02 00:23:56

我对public void results(double total)进行了修改,使其接受一个double,并且成功地运行了。

你确定这是你所有的代码吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17415413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档