-3

Here is the code I have.

//input

    System.out.println("Using numbers, in what month were you born? ");

    String **userMonth** = input.nextLine();

// also tried int **userMonth** = input.nextInt();

It does not work either way.

userMonth will not "activate?" (sorry noob and don't know all terms)

When tried to call later in program error:

    if (userMonth < 3) {
    System.out.println("Your vacation home is a van down by a river!"); 
    }

//userMonth cannot be resolved to variable

Lee Powell
  • 23
  • 3
  • Does this answer your question? [How do I convert a String to an int in Java?](https://stackoverflow.com/questions/5585779/how-do-i-convert-a-string-to-an-int-in-java) – Gautham M Mar 14 '21 at 15:27
  • No my code is not making userMonth into an object where when I try to reference it later it does not connect to the variable. – Lee Powell Mar 14 '21 at 15:48
  • 1
    Could you please post the full code. are you using `userMonth<3` in the same method where you do `String userMonth = input.nextLine();` ? – Gautham M Mar 14 '21 at 15:52

1 Answers1

2

Very odd that your variables are showing up as **varName** instead of varName.

  • First use:
int userMonth = 0; // initialize variable.
userMonth = input.nextInt();

But it does not consume the newline ('ENTER').

  • Therefore, immediately after, consume the newline character via:
input.nextLine();
  • Also make sure Scanner was declared as
Scanner input = new Scanner(System.in);
  • Don't forget to close the scanner at the end of program
input.close();
mindoverflow
  • 730
  • 4
  • 13