I have an "Exception in thread" error. I create a public class student
and give it three classes: NAME of student, ID of student and GPA of student. When I run the code and enter information for student1 it's good. But when I enter student2, the code skips the name for student2, and gives me the student id and GPA. How can I remedy this?
Here is the code:
import java.util.Scanner;
class Student {
public String name;
public int id;
public float gpa;
}
public class learning {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Student s1 = new Student();
System.out.print("Enter your name: ");
s1.name = input.nextLine();
System.out.print("Enter your id: ");
s1.id = input.nextInt();
System.out.print("Enter your gpa: ");
s1.gpa = input.nextFloat();
Student s2 = new Student();
System.out.print("Enter your name: ");
s2.name = input.nextLine();
System.out.print("Enter your id: ");
s2.id = input.nextInt();
System.out.print("Enter your gpa: ");
s2.gpa = input.nextFloat();
Student s3 = new Student();
System.out.print("Enter your name: ");
s3.name = input.nextLine();
System.out.print("Enter your id: ");
s3.id = input.nextInt();
System.out.print("Enter your gpa: ");
s3.gpa = input.nextFloat();
System.out.println("your name: " + s1.name + "\n"
+ "your id: " + s1.id + "\n"
+ "your GPA: " + s1.gpa);
}
}