Adam
Adam

Reputation: 3

<identifier> expected - Indentation?

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);
        {

        }

I get an expected error down by int a and int b. Is it the indentation? I'm not sure what to do. I tried moving around the indentation and the brackets with no avail. I'm new at this and I'm stumped. I feel like it's a really simple problem.

Upvotes: 1

Views: 70

Answers (2)

Abhi
Abhi

Reputation: 6588

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;

    }

For your Problems see the syntax for

  1. System.out.println
  2. How to code a method and return a value
  3. Declaring methods inside classes
  4. All the best

Upvotes: 0

Pete Mitchell
Pete Mitchell

Reputation: 91

Indentation matters only for readability. You have three issues that I can see:

  1. You have no closing '}' on the entire class
  2. Your max() method is a definition and should not have a ';' after it
  3. Move the opening '{' in your max method above the logic of the method.

Hope this helps.

Upvotes: 1

Related Questions