Java program to get mark from the file and calculate average

 //Create the file in folder and store rollno. Name mark in same line


public class FileMark

{

public static void main(String[] args) throws FileNotFoundException, IOException {

FileReader file= new FileReader (" (File location ).txt"); 

BufferedReader bf= new BufferedReader(file);

String st= bf.readLine();

int sum=0;

float avg= 0.0;

while((st=bf.readLine()) !=null) {

StringTokenizer stn= new StringTokenizer (st);

String rn=stn.nextToken();

String name=stn.nextToken();

int phy=Integer.parseInt(stn.nextToken());

int chem=Integer.parseInt(atn.nextToken());

int bio=Integer.parseInt(atn.nextToken());

int math=Integer.parseInt(stn.nextToken());

sum=sum+phy+chem+bio+math;

avg= sum/5;

System.out.println("Roll number:" +rn);

System.out.println("Name:"+name);

System.out.println("Total mark:"+sum);

System.out.println("Average is "+avg);

System.out.println("_______________________________________");

}

}

}

Comments

Popular Posts