首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 ><identifier>期望-缩进?

<identifier>期望-缩进?
EN

Stack Overflow用户
提问于 2015-06-10 20:08:22
回答 2查看 56关注 0票数 1
代码语言:javascript
复制
public class CoinFlip {
        public static void main(String[] args) {
            //Get a random number
            //Decide the outcome of the coin flip
            //Get a second random number
            //Decide the outcome of a second coin flip
            //Print out which flip had a higher score
            //Print out the maximum of the two flips
            double myNumber;

            myNumber = Math.random();
        int score;
        if (myNumber < .4) {
                System.out.println("heads");
                score = 5;
        }
        else if (myNumber <.8) {
                System.out.println("tails");
                score = 2;
        }
        else if (myNumber <.85) {
                System.out.println("derr");
                score = 20;
        }
        else {
                System.out.println("go 2 sleep");
                score = -3;
        }

        System.out.println("arrgh the score for der flip wus: " + score);

        }
        public static int max(int a, int b);
            int a = score;
            int b = secondScore;
                int maxScore = Math.max(score, secondScore);
                    System.out.println(score, secondScore);
        {

        }

我得到了int a和int b的预期错误,这是缩进吗?我不知道该怎么办。我试着在凹痕和托架周围移动,但没有结果。我是新来的,我很困惑。我觉得这是个很简单的问题。

EN

回答 2

Stack Overflow用户

发布于 2015-06-10 20:16:11

缩进只对可读性很重要。你有三个问题我看得出来:

  1. 整个类都没有“}”的结尾
  2. max()方法是一个定义,在它之后不应该有';‘
  3. 将max方法中的开头“{”移至该方法的逻辑上方。

希望这能有所帮助。

票数 1
EN

Stack Overflow用户

发布于 2015-06-10 20:13:43

代码语言:javascript
复制
public class CoinFlip {
    public static void main(String[] args) {
        // Get a random number
        // Decide the outcome of the coin flip
        // Get a second random number
        // Decide the outcome of a second coin flip
        // Print out which flip had a higher score
        // Print out the maximum of the two flips
        double myNumber;

        myNumber = Math.random();
        int score;
        if (myNumber < .4) {
            System.out.println("heads");
            score = 5;
        } else if (myNumber < .8) {
            System.out.println("tails");
            score = 2;
        } else if (myNumber < .85) {
            System.out.println("derr");
            score = 20;
        } else {
            System.out.println("go 2 sleep");
            score = -3;
        }

        System.out.println("arrgh the score for der flip wus: " + score);

    }

    public static int max(int score, int secondScore) {
        int a = score;
        int b = secondScore;
        int maxScore = Math.max(a, b);
        System.out.println("Score 1 = " + score + " Score 1 = " + secondScore);
        return maxScore;

    }

有关问题,请参见

  1. System.out.println
  2. 如何编写方法代码并返回值
  3. 在类中声明方法
  4. 万事如意
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30766312

复制
相关文章

相似问题

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