-1

Trying to figure out why my String userString = ""; is not recognized. All of my other variable types show up as a different color.

Thanks

import java.util.Scanner;

  public class BasicInput {
  public static void main (String [] args) {
  Scanner scnr = new Scanner(System.in);
  int userInt = 0;
  double userDouble = 0.0;
  char userChar = 'a';
  String userString = "";

  System.out.println("Enter integer: ");
  userInt = scnr.nextInt();

  System.out.println("Enter double: ");
  userDouble = scnr.nextDouble();

  System.out.println("Enter character: ");
  userChar = scnr.next().charAt(0);

  System.out.println("Enter string: ");
  userString = scnr.nextLine();

  System.out.println(userInt + " " + userDouble + " " + userChar + " " + userString);

  return;
  }
}

1 Answers1

0

Runing the Code this is the output:

Enter integer: 
1
Enter double: 
22
Enter character: 
b
Enter string: 
1 22.0 b //Skips the userString = scnr.nextLine(); and jumps to the last println

For some reason when i run the program, using differents .nextLine... .nextInt .next it skips to read the last line, using just .nextLine and then using a method to check if the String is a double integer or char can resolve this