I was learning about input in Java. I used IntelliJ to write and run my code. But it keeps skipping a line. I run that line separately, and it worked fine.
The skipped line is:
String fullName = scanner.nextLine().trim();
Full code:
class main {
public static void main(String args[]) {
// 16- Reading Input
System.out.println("\n16- Reading Input");
Scanner scanner = new Scanner(System.in);
System.out.print("Input your age: ");
byte age = scanner.nextByte();
System.out.println("You are " + age + " years old.");
System.out.print("\nInput your name: ");
String name = scanner.next();
System.out.println("your name is: " + name);
System.out.print("\nFull Name: ");
String fullName = scanner.nextLine().trim();
System.out.println("You are " + fullName);
}
}
The result is like below:
16- Reading Input
Input your age: 35
You are 35 years old.
Input your name: kevin
your name is: kevin
Full Name: You are