Here is the program I have so far for the Pick A Card assignment. It almost works but gives the wrong answer? Is something backwards in my code?
import java.util.*; public class assign_7 { static Scanner js = new Scanner(System.in); public static void main (String[] args) { int num1, num2; int guess; char choice; String aString; num1 = (int) (Math.random() * 100); num2 = (int) (Math.random() * 100); System.out.println("Enter 1 to see card 1 OR enter 2 to see card 2:"); guess = js.nextInt(); // Player picks card 1 if (guess == 1) { guess = num1; System.out.println("You picked card 1, which has the value of " + num1); System.out.println("Is this the highest card? (y/n)"); aString = js.next(); choice = aString.charAt(0); System.out.println(); if ((aString.equals ("y")) && (num1 < num2)) System.out.println("Correct. The other card is " + num2); if ((aString.equals ("y")) && (num1 > num2)) System.out.println("Incorrect. The other card is " + num2); if ((aString.equals ("n")) && (num1 < num2)) System.out.println("Correct. The other card is " + num2); else if ((aString.equals ("n")) && (num1 > num2)) System.out.println("Incorrect. The other card is " + num2); } // Player picks card 2 if (guess == 2) { guess = num2; System.out.println("You picked card 2, which has the value of " + num2); System.out.println("Is this the highest card? (y/n)"); aString = js.next(); choice = aString.charAt(0); System.out.println(); if ((aString.equals ("y")) && (num1 < num2)) System.out.println("Incorrect. The other card is " + num1); if ((aString.equals ("y")) && (num1 > num2)) System.out.println("Correct. The other card is " + num1); if ((aString.equals ("n")) && (num1 < num2)) System.out.println("Incorrect. The other card is " + num1); else if ((aString.equals ("n")) && (num1 > num2)) System.out.println("Correct. The other card is " + num1); } } }