lundi 30 septembre 2019

New to Java. What am I doing wrong? (while-loop with nested if-else) [duplicate]

This question already has an answer here:

I am working on a program using Java and I am having some problems compiling my program. The purpose of the program is to code a while-loop with a nested if-else structure within an if-else structure. (1) There is an error on line 13 that says ".class expected", "illegal start of expression", and "; expected". (2) Am I correctly nesting the if-else structure so far? (3)Are the curly brackets correctly placed?

/**
* @author Sean Ramos
* @version1.0 9/30/2019 1:30PM 
* PURPOSE: To use a while-loop with a nested if-else structure within an if-else structure.
*/
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=
char tryAgain='Y';
char tryAgain2='Y';
String q1="%nWhat is the password?";
String q2="%nEnter your age: ";

while(Character.toUpperCase(tryAgain1)=='Y'){

 System.out.printf(q1);
 String password=input.nextLine();
 if(password!="MonthyPython")
 { 
   System.out.printf("%nInvalid password!%nDo you want to try again? Y or N.");
   tryAgain=input.nextLine().charAt(0);
 }
 else
 { if(password=="MonthyPython")
 { 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);
 }}}}}
  System.exit(0); 
 } //End main()

 } //End class

Aucun commentaire:

Enregistrer un commentaire