Hello
I have updated my code, please check and if you have any ideas on this do post back. I need a help in my program logic. I have posted by code below.
Code:
public static void main(String[] args)
{
Scanner keyb = new Scanner(System.in);
int guess1, guess2, guess3;
int correct = 0;
int rn1 = 1; //(int)(Math.random() * 10);
int rn2 = 2; //(int)(Math.random() * 10);
int rn3 = 3; //(int)(Math.random() * 10);
System.out.print("Please providde the First guess between 0 an 9 - ");
guess1 = keyb.nextInt();
System.out.print("Please providde the Second guess between 0 an 9 - ");
guess2 = keyb.nextInt();
System.out.print("Please providde the Third guess between 0 an 9 - ");
guess3 = keyb.nextInt();
if(guess1 == rn1 || guess1 == rn2 || guess1 == rn3)
{
correct += 1;
if (guess2 == rn1 || guess2 == rn2 || guess2 == rn3)
{
correct += 1;
if (guess3 == rn1 || guess3 == rn2 || guess3 == rn3)
{
correct += 1;
if ( guess1 == rn1 && guess2 == rn2 && guess3 == rn3)
{
correct += 1;
}
}
}
}
switch(correct)
{
case 0:
{
System.out.println("You have won $0 because you matched NO Numbers in the sequence");
break;
}
case 1:
{
System.out.println("You have won $10 because you matched One Number in the sequence");
break;
}
case 2:
{
System.out.println("You have won $100 because you matched TWO Numbers in the sequence");
break;
}
case 3:
{
System.out.println("You have won $1000 because you matched THREE Numbers in the sequence");
break;
}
case 4:
{
System.out.println("You have won $1,000,000 because you matched THREE Numbers in PERFECT SEQUENCE");
break;
}
}
System.out.println("Random Number = " + rn1 + " Users Guess = " + guess1);
System.out.println("Random Number = " + rn2 + " Users Guess = " + guess2);
System.out.println("Random Number = " + rn3 + " Users Guess = " + guess3);
}
Bookmarks