9.3k views
4 votes
MAKE THE CHANGES

import java.lang.Math;
class Main {
public static void main(String[] args) {
int max = 9;
int min = 0;
int loops = 3;
int coin1 = 0;
int coin2 = 0;

for (int i =0;i = coin2)){
System.out.println("WOW! Two coins the same!");
} else {
System.out.println("No matches");
}

//CHALLENGE #3 Change the code below to say WOW if at least 1 coin is heads (1, not 0)
// You only need to change the conditions.
if (( coin1 !=3 ) && ( coin2 >= 4)){
System.out.println("WOW! At least one coin is heads");
} else {
System.out.println("neither coin is heads");
}

//CHALLENGE #4 Change the code below to say WOW if both coins are heads
// You only need to change the conditions.
if (( coin1 != 1) || (coin2 <= 3)){
System.out.println("WOW! Both coins are Heads!");
} else {
System.out.println("No matches");
}
}
}
}

User Wwl
by
8.2k points

1 Answer

2 votes

Answer:

import java.lang.Math;

class Main {

public static void main(String[] args) {

int max = 9;

int min = 0;

int loops = 3;

int coin1 = 0;

int coin2 = 0;

for (int i =0; i < loops; i++) {

coin1 = (int) (Math.random() * (max - min + 1) + min);

coin2 = (int) (Math.random() * (max - min + 1) + min);

System.out.println("Coin 1: " + coin1 + ", Coin 2: " + coin2);

// CHALLENGE #1: Change the code below to say WOW if both coins are even

if (coin1 % 2 == 0 && coin2 % 2 == 0) {

System.out.println("WOW! Both coins are even!");

} else {

System.out.println("No matches");

}

// CHALLENGE #2: Change the code below to say WOW if both coins are the same

if (coin1 == coin2) {

System.out.println("WOW! Two coins the same!");

} else {

System.out.println("No matches");

}

// CHALLENGE #3: Change the code below to say WOW if at least 1 coin is heads (1, not 0)

if (coin1 == 1 || coin2 == 1) {

System.out.println("WOW! At least one coin is heads");

} else {

System.out.println("Neither coin is heads");

}

// CHALLENGE #4: Change the code below to say WOW if both coins are heads

if (coin1 == 1 && coin2 == 1) {

System.out.println("WOW! Both coins are heads!");

} else {

System.out.println("No matches");

}

}

}

}

Step-by-step explanation:

User Gaurang S
by
8.5k points