I want to read an int, double and string and add each one to a variable but I can't read the string.
int i = 4;
double d = 4.0;
String s = "My name is ";
Scanner scan = new Scanner(System.in);
int i2 = scan.nextInt();
double d2 = scan.nextDouble();
String s2 = scan.nextLine();
System.out.println(i+i2);
System.out.println(d+d2);
System.out.println(s + s2);
scan.close();
my understanding is that scan.nextLine()
reads a string but it just skips it.
scan.next()
just reads the first word.
it works properly if i added scan.nextLine();
before String str2 = scan.nextLine();
but i dont know why