In an examination, a pupil appears for three subjects viz Physics, Chemistry and Biology. Write a program to input the name of the pupil, marks in the three subjects, and calculate the total marks, average marks and percentage of marks obtained. Display the marks after rounding them off.
How to do this program in Java?
Answers
Answer:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("What is your name: ");
String name = scanner.nextLine();
System.out.println("Enter marks in physics: ");
int p = scanner.nextInt();
System.out.println("Enter marks in chemistry: ");
int c = scanner.nextInt();
System.out.println("Enter marks in biology: ");
int b = scanner.nextInt();
int totalMarks = p+c+b;
int avgMarks = totalMarks/3;
System.out.println("Student name: " + name);
System.out.println("Total Marks: " + totalMarks);
System.out.println("Average Marks: " + avgMarks);
}
}