In this post, we will see simple java program to find average and percentage marks.
We have taken average and percentage of five subject marks below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import java.util.Scanner; public class MarksCalculator { public static void main(String args[]) { int markArray[] = new int[5]; int i; float sum=0; float average, percentage; Scanner scan = new Scanner(System.in); System.out.print("Enter marks for 5 Subjects : "); for(i=0; i<5; i++){ markArray[i] = scan.nextInt(); sum = sum + markArray[i]; } average = sum/5; percentage = (sum/500) * 100; System.out.print("Average Marks = " +average); System.out.print("\nPercentage = " +percentage+ "%"); } } |
Output:
Enter marks for 5 Subjects : 91 57 83 69 74
Average Marks = 74.8
Percentage = 74.8%
Average Marks = 74.8
Percentage = 74.8%
That’s all about Java program to calculate average and percentage of marks.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.