mardi 6 octobre 2020

How to fix Else without if error in Java? [closed]

Although i reviewed other similar questions, I stillc cant seem to know why this error keeps popping although the else if is connected to the previous if and has it's own indentation . This is the conditional part of the code

    if (!scnr.hasNextLine()) {
      System.out.println("Hello, " + "stranger" + "!"); 
     
      } 
  
   String name = scnr.nextLine().trim();

   else if  (name == null || name.equals("")) {
        System.out.println("Hello, " + "stranger" + "!");
    }

    else {

        System.out.println("Hello, " + name + "!");
    }

Aucun commentaire:

Enregistrer un commentaire