Welcome to Westonci.ca, your ultimate destination for finding answers to a wide range of questions from experts. Get immediate and reliable answers to your questions from a community of experienced professionals on our platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

Please help me with this java program below. I am receiving errors when I run it

Java program below

import java.util.Random;

public class Coin {
private static String sideUp;

void Coin() {

toss();

}

public static void toss() {
Random in = new Random();
int x = in.nextInt();
if (x % 2 == 0)
sideUp = "heads";
else
sideUp = "tails";
}

public static String getFace() {
return sideUp;
}

public static void main(String[] args) {
int tail = 0, head = 0;
Coin coin = new Coin();
System.out.println("Initial side of coin: " + coin.getFace());
System.out.println("\nTossing coin 20 times:-");
for (int i = 1; i <= 20; i++) {
coin.toss();
if (coin.getFace().equals("tails"))
tail++;
else
head++;
System.out.println("Time " + (i) + " : " + coin.getFace());
}
System.out.println("\nTails Outcome: " + tail);
System.out.println("Heads Outcome: " + head);
}
}


Sagot :

Thank you for visiting our platform. We hope you found the answers you were looking for. Come back anytime you need more information. We hope you found what you were looking for. Feel free to revisit us for more answers and updated information. We're dedicated to helping you find the answers you need at Westonci.ca. Don't hesitate to return for more.