I need to create an object array and read the values of the elements in the constructor from console. I am totally confused how to do it.Can anyone give a clarity about how to do it
public class Student { int id; String name; double marks; public Student(int id, String name, double marks) { id = this.id; name = this.name; marks = this.marks; } } public class Solution { public static void main(String[],args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); Student[] arr=new Student[n]; for(int i=0;i<n;i++) { int x =sc.nextInt(); String y=sc.nextLine(); double z=sc.nextDouble(); arr[i]=arr.Student(x,y,z); } } } I am confused on how to call the constructor. Can anyone help me?
arr[i]=new Student(x,y,z);id = this.id;should bethis.id = id;(same for the other 2 variables)