Hi I'm a beginner in java. I have some problem with my code.
can someone help me?
import java.util.Scanner; public class HW11of2 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner console = new Scanner(System.in); student[] students=new student[4]; for(int i=0;i<students.length;i++){ System.out.println("Please enter the name: "); students[i].name = console.nextLine(); System.out.println("Please enter a number for the id: "); students[i].id = console.nextInt(); int sum=0; for(int j=0;j<5;j++){ System.out.println("Please enter the grade: "); students[i].grades[j] = console.nextInt(); sum=sum+ students[i].grades[j]; } students[i].avg=sum/5; } int avgtotal=0; for(int i=0;i<students.length;i++){ avgtotal=avgtotal + students[i].grades[2]; } System.out.println(avgtotal); int min=min(students[0].grades); for(int i=1;i<students.length;i++){ int temp=min(students[i].grades); if(temp<min){ min=temp; } } int max=max(students[0].grades); for(int i=1;i<students.length;i++){ int temp=max(students[i].grades); if(temp>max){ max=temp; } } console.close(); } public static int min(int[] x){ int min=x[0]; for (int i=0; i<x.length;i++) { if (x[i]<min) { min=x[i]; } } return min; } public static int max(int[] x){ int max=x[0]; for (int i=0; i<x.length;i++) { if (x[i]>max) { max=x[i]; } } return max; } public class student { int id; String name; int[] grades=new int[5]; int avg; } }
and the error I get is:
Exception in thread "main" java.lang.NullPointerException at HW11of2.main(HW11of2.java:13)
Thanks!