Reputation: 3
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
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
Upvotes: 0
Reputation: 91
Indentation matters only for readability. You have three issues that I can see:
Hope this helps.
Upvotes: 1