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得到预期的错误。是缩进吗?我不知道该怎么做。我试图在缩进和括号周围移动无济于事。我是新来的,我很难过。我觉得这是一个非常简单的问题。
答案 0 :(得分:1)
缩进只是为了便于阅读。您有三个问题我可以看到:
希望这有帮助。
答案 1 :(得分: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;
}
对于您的问题,请参阅
的语法