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的预期错误,这是缩进吗?我不知道该怎么办。我试着在凹痕和托架周围移动,但没有结果。我是新来的,我很困惑。我觉得这是个很简单的问题。
发布于 2015-06-10 20:16:11
缩进只对可读性很重要。你有三个问题我看得出来:
希望这能有所帮助。
发布于 2015-06-10 20:13:43
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;
}有关问题,请参见
https://stackoverflow.com/questions/30766312
复制相似问题