2015-06-10 2 views
1
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. Это отступы? Я не уверен, что делать. Я попытался передвигаться по отступу и скобкам безрезультатно. Я новичок в этом, и я в тупике. Я чувствую, что это очень простая проблема.<identifier> ожидается - отступы?

+0

В вашем методе 'max', где вы определяете переменные' score' и 'secondScore'? – azurefrog

+0

Вы не можете назвать локальные переменные именами параметров. Голосование закрывается как тривиальная проблема синтаксиса. – dasblinkenlight

+0

Int a и int b part. Я не уверен, что это правда. – Adam

ответ

0
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

Вы должны добавить какую-то квалификацию/пояснение для этого кода. – tnw

1

Отступ имеет значение только для удобства чтения , У вас есть три вопроса, которые я могу видеть:

  1. У вас нет закрытия «}» на всем классе
  2. метода
  3. Ваших максимальный() является определением и не должен иметь «;» после этого
  4. Переместите открытие '{' в своем методе максимума над логикой метода.

Надеюсь, это поможет.

+0

1 да, 2 не существует, 3 не вызовет никаких проблем – tnw

+1

Ugh, nvm. Плохой редактор изменил часть кода. Откат назад – tnw

+0

Был/был до того, как он был отредактирован ... :) –