0

So I recently started learning java and i came across this issue. This string input does not get executed at all. Integer inputs work just fine but for some reason it just skips that line of code when it's a string input.

import java.util.Scanner;

class Student{
    String name;
    int age;
    int ID;

    void speak() {
        System.out.println("Hello i am "+name);
    }

    int getID(){
        return ID;
    }

    public void setName(String newName){
        name = newName;
    }

}

public class Main {
    public static void main(String[] args) {
       Student ex1 = new Student();
       Scanner input = new Scanner(System.in);


        System.out.println("Please enter Student info: ");
        System.out.println("Student name: "); ex1.name = input.nextLine();
        System.out.println("Student age: "); ex1.age = input.nextInt();
        System.out.println("Student ID: "); ex1.ID = input.nextInt();

        System.out.println("deb");
        String test =input.nextLine();
        System.out.println("deb");




    }
}

0 Answers0