What is Wrong with my code
well it works except it always shows the else part of the statement
Code Java:
import java.util.Scanner;
import java.util.Random;
public class eightball
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
Random random = new Random();
int z;
System.out.println("type in your yes or no question");
scan.nextLine();
z = random.nextInt(20) + 1;
int w = (z);
System.out.println("the anser to your Question is ");
if (w < 4)
System.out.print("Yes.");
if (w < 8 && w > 4)
System.out.print(" No.");
if (w < 12 && w > 8)
System.out.print(" it could happen");
if (w < 16 && w > 12)
System.out.print(" can not tell");
else
System.out.print(" never");
}
}
Re: What is Wrong with my code
Try
Code Java:
import java.util.Scanner;
import java.util.Random;
public class eightball {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random random = new Random();
int z;
System.out.println("type in your yes or no question");
scan.nextLine();
z = random.nextInt(20) + 1;
int w = (z);
System.out.println("the anser to your Question is ");
if (w < 4)
System.out.print("Yes.");
else if (w < 8 && w > 4)
System.out.print(" No.");
else if (w < 12 && w > 8)
System.out.print(" it could happen");
else if (w < 16 && w > 12)
System.out.print(" can not tell");
else
System.out.print(" never");
}
}