I am working on a program using Java, and I am getting errors. The purpose of the program is to code a while loop with a nested if-else structure within an if-else structure.
There is an error on line 33 that says "variable age might not have been initialized" even though it is declared in the main()?
Am I correctly nesting the if-else structures inside the while?
Are the curly brackets correctly placed?
import java.util.Scanner; public class RamosSLE32 { //Begin class public static void main(String[] args) { //Begin main() Scanner input = new Scanner(System.in); int age; String correctPassword = "MonthyPython"; char tryAgain = 'Y'; char tryAgain2 = 'Y'; String q1 = "%nWhat is the password?"; String q2 = "%nEnter your age: "; while (Character.toUpperCase(tryAgain) == 'Y') { System.out.printf(q1); String password = input.nextLine(); if (!password.equals(correctPassword)) { System.out.printf("%nInvalid password!%nDo you want to try again? Y or N."); tryAgain = input.nextLine().charAt(0); } else { if (password.equals(correctPassword)) { System.out.printf(q2); age = input.nextInt(); } { if (age > 17) { System.out.printf("%nShangri-La welcomes you to your earthly paradise!%nThank you! Have a nice day!"); } else { if (age <= 17) { System.out.printf("%nSorry, NO underaged patrons allowed!%nDo you want to try again? Y or N."); tryAgain2 = input.nextLine().charAt(0); } } } } } } // End main() } // End class