Design and Develop a java program to read marks of a student and print the total and average of marks using scanner class.
Program Code:
import java.util.*;
import java.io.*;
class Student
{
public static void main(String args[])
{
Scanner sc=new Scanner (System. in);
int marks[]=new int[5];
float total=0,avg;
for (int i=0;i<5;i++)
{
System.out.println (“Enter marks”);
marks[i]=sc.nextInt();
}
for(int i=0;i<5;i++)
{
total+=marks[i];
}
avg=total/5;
System.out.println(“ Total is”+total);
System.out.println(“ Avg is”+avg);
}
}
Output:
Enter marks
55
Enter marks
66
Enter marks
77
Enter marks
88
Enter marks
99
Total is 385.0
Avg is 77.0
Post A Comment:
0 comments: