-2

I'm doing a small project and I have everything done, just one small error. the error shows "symbol not found" and shows the red squiggly line under my scan.

package pkgif.elsestatements.java;

import java.util.Scanner;
public class IfElseStatementsJava {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner user_input = new Scanner(System.in);

        String your_name;
        System.out.print("What is your name?");
        your_name = user_input.next();

         System.out.println("Hi " + your_name);

         String user_input2;
        System.out.print(".");
        user_input2 = user_input.next();

         System.out.println("Do you like Gospel Music Paul?"); //Asks question

     String input = scan.nextLine(); //Waits for input
     if (input.equalsIgnoreCase("Yes")) { //If the input is Yes)
          System.out.println("Here are some songs; Amazing Grace, I'll Fly Away, A Little Talk With Jesus ");
     }
     else { //If the input is anything else
          System.out.println("Ok! Have a nice day!");



    }

}

this line is the one giving me trouble ---- String input = scan.nextLine(); //Waits for input

I was feeling really great about finish this with no errors beforehand, then this. Any help is appreciated.

YCF_L
  • 49,027
  • 13
  • 75
  • 115
Timothy
  • 3
  • 3
  • 2
    did you mean `String input = user_input.nextLine();` – YCF_L Jan 15 '18 at 18:08
  • `scan` is undefined, because you named the `Scanner` variable `user_input`. – Andreas Jan 15 '18 at 18:09
  • 1
    Once you fix the compile error, you'll run into this issue: [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/q/13102045/5221149) – Andreas Jan 15 '18 at 18:10

1 Answers1

2

According to the code above. You've defined Scanner user_input = new Scanner(System.in); i.e. user_input as the oject ref. So, changing String input = scan.nextLine(); to String input = user_input.nextLine(); should do.

Neha
  • 2,291
  • 2
  • 9
  • 25
  • This fixed my problem, Thx!!! This is my first time messing with any software like this, so forgive me if i overlook anything like this. – Timothy Jan 16 '18 at 00:55