
import java.io.*;
class Studar{
public static void main(String ar[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("how many subjects");
int n= Integer.parseInt(br.readLine());
//create array for marks
int marks[]=new int[n];
int tot=0;
for(int i=0;i<n;i++){
System.out.println("enter marks:\n");
marks[i]=Integer.parseInt(br.readLine());
}
for(int i=0;i<n;i++){
tot=tot+marks[i];}
System.out.println("tot marks="+tot);
float percent= (float)tot/n;
System.out.println("percentage="+percent);
}
}

Hi Friend,
import java.io.*;
class Studar{
public static void main(String ar[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("how many subjects");
int n= Integer.parseInt(br.readLine());
int marks[]=new int[n];
int tot=0;
System.out.println("Enter marks of "+n+" subjects: ");
for(int i=0;i<marks.length;i++){
int m=Integer.parseInt(br.readLine());
marks[i]=m;
tot+=marks[i];
}
System.out.println("Total Marks: "+tot);
}
}
The given code reads the number of subjects from the console and according create an array in order to store the marks of each subject and calculate the total marks.
The InputStreamReader(System.in) allow the user to input and the method readLine() of BufferedReader class read the number of subjects from the console. By using the Integer.parseInt(), the no of subject get converted into number. An array is created to store the marks of each subject whose length is the number of subjects. The method Integer.parseInt(br.readLine()), reads the marks of each subject eneterd by user. A variable tot is defined to store the sum of all the marks.
Thanks