I am a beginner experimenting with user input and data types. My program, chatbot, has an error in it that I cannot find. When run, it collects my name and age, but then skips right over prompting for my favorite pasttime, as if I had pressed the "enter" key prematurely. It then goes to the next question. I believe that this error has something to do with my use of the 'byte' data type, but I don't know how to fix it.
Here is my code:
import java.util.Scanner; public class ChatBot { public static void main(String[] args) { Scanner in = new Scanner(System.in); String name; System.out.print("What is your name? "); name = in.nextLine(); System.out.println("Hello, " + name + ". "); byte age; System.out.print("How old are you? "); age = in.nextByte(); \\ Here is where it skips ahead in the code. System.out.println("So, you're " + age + " years old? "); String hobby; System.out.print("What is your favorite hobby? "); hobby = in.nextLine(); System.out.println("So, you like " + hobby + "? "); \\ Here is where it picks up. It does prompt for my mother's name, but not my hobby. String mother; System.out.print("What is your mother's name? "); mother = in.nextLine(); System.out.println("So, your mother's name is " + mother + ". "); } }