I ty to use arrays for storing student information. but when I run this code it's doesn't allow me to input student name. it jumpes from ID to sex by missing name. I don't know to fix this problem. Here is my code:
import java.util.Scanner;
// class student
class Student{
private int ID;
private String name;
private String sex;
private float score;
Student(){}
// function to input student information
public void Input(){
Scanner IN = new Scanner(System.in);
System.out.print("Enter ID : ");
ID = IN.nextInt();
System.out.print("Enter name : ");
name = IN.nextLine();
System.out.print("Enter sex : ");
sex = IN.nextLine();
System.out.print("Enter score: ");
score = IN.nextFloat();
}
// function to output student information
public void Output(){
System.out.println(ID + "\t" + name + "\t" + sex + "\t" + score + "\n");
}
}
public class Main {
public static void IOStudent(){
Scanner IN = new Scanner(System.in);
int n;
int i;
System.out.print("Please enter number of student: ");
n = IN.nextInt();
System.out.println("Enter student information: ");
Student []std = new Student[n];
for(i = 0; i<n; i++){
std[i] = new Student();
std[i].Input();
}
System.out.println("All students information: ");
for(i = 0; i<n; i++){
std[i].Output();
}
}
public static void main(String[] args) {
IOStudent();
}
}