hi, im new to java console programming and i needed a solution to what is likely very simple problem.
every time i try running the program, it gives me an error saying
"the variables strCard1 and strCard2 may be accessed here before having been assigned definite values".
i'm trying to display the numbers the integers intCard1 and intCard2 generate with a card name (eg. Ace(1), King(10)) using the string values strCard1 and strCard2.
it's the last line before the comments at the end causing the error.
(using ReadyToProgramJava and Holt's output console)
// The "Blackjack" class. import java.awt.*; import hsa.Console; import java.text.*; import java.util.Random; public class Blackjack { static Console c; // The output console public static void main (String[] args) { c = new Console (); Random randomGenerator = new Random (); int intCard1, intCard2, intCardTotal, intFace1, intFace2; String strCard1, strCard2; //determine 1st card intCard1 = randomGenerator.nextInt (10) + 1; //Generate random number between 1 to 11. switch (intCard1) { case 1: strCard1 = ("Ace (1)"); break; case 2: strCard1 = ("Two(2)"); ; break; case 3: strCard1 = ("Three(3)"); break; case 4: strCard1 = ("Four(4)"); break; case 5: strCard1 = ("Five(5)"); break; case 6: strCard1 = ("Six(6)"); break; case 7: strCard1 = ("Seven(7)"); break; case 8: strCard1 = ("Eight(8)"); break; case 9: strCard1 = ("Nine(9)"); break; case 10: intFace1 = randomGenerator.nextInt (2) + 1; //Generate random number between 1 to 3. switch (intFace1) { case 1: strCard1 = ("Jack(10)"); break; case 2: strCard1 = ("Queen(10)"); break; case 3: strCard1 = ("King(10)"); break; } break; case 11: strCard1 = ("Ace(11)"); break; } //determine 2nd card intCard2 = randomGenerator.nextInt (10) + 1; //Generate random number between 1 to 11. switch (intCard2) { case 1: strCard2 = ("Ace (1)"); break; case 2: strCard2 = ("Two(2)"); ; break; case 3: strCard2 = ("Three(3)"); break; case 4: strCard2 = ("Four(4)"); break; case 5: strCard2 = ("Five(5)"); break; case 6: strCard2 = ("Six(6)"); break; case 7: strCard2 = ("Seven(7)"); break; case 8: strCard2 = ("Eight(8)"); break; case 9: strCard2 = ("Nine(9)"); break; case 10: intFace2 = randomGenerator.nextInt (2) + 1; //Generate random number between 1 to 3. switch (intFace2) { case 1: strCard2 = ("Jack(10)"); break; case 2: strCard2 = ("Queen(10)"); break; case 3: strCard2 = ("King(10)"); break; } break; case 11: strCard2 = ("Ace(11)"); break; } c.println ("You were dealt a(n) " + strCard1 + " and a(n) " + strCard2); // Place your program here. 'c' is the output console } // main method } // Blackjack class