22. Java Program to Read Marks of 3 Subjects and Display the Total, Average.
How does this program work?
- In this program you are going to learn about How to find Sum of 3subjects and their average using java.
- Take User inputs for Marks of 3subjects and store them in 3different variables.
- find out the total and averages values and display using java.
Here is the code
// Read Marks
import java.util.Scanner;public class Marks
{
public static void main(String args[])
{
int t,h,e,total;
float avg;
System.out.println("Enter Telugu,English,Hindi Marks:" );
Scanner obj1=new Scanner(System.in);
t=obj1.nextInt();
h=obj1.nextInt();
e=obj1.nextInt();
total=(t+h+e);
avg=total/3;
System.out.println("Total Marks of 3 subjects :" +total);
System.out.println("Average Marks of 3 subjects :" +avg);
}
}