0% found this document useful (0 votes)
43 views

Calculate Average and Percentage Marks in Java

The document explains how to calculate the average and percentage marks of a student in Java by asking the user to enter marks for 5 subjects, summing the marks, calculating the average as the sum divided by 5, and calculating the percentage as the sum divided by 500 multiplied by 100.

Uploaded by

sonam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Calculate Average and Percentage Marks in Java

The document explains how to calculate the average and percentage marks of a student in Java by asking the user to enter marks for 5 subjects, summing the marks, calculating the average as the sum divided by 5, and calculating the percentage as the sum divided by 500 multiplied by 100.

Uploaded by

sonam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Calculate Average and Percentage Marks in Java

To calculate average and percentage marks of a student in Java programming, you have to
ask to the user to enter marks obtained in some subjects (say 5). Place summation of 5
subject's marks in a variable say sum and place sum/5 in a variable say avg then place
sum/500*100 in a variable say perc, then display the result on the output screen.

Java Programming Code to Calculate Average and Percentage Marks

Following Java Program ask to the user to enter the marks obtained in 5 subjects to
calculate and display the average and percentage marks :

/* Java Program Example - Calculate Average and Percentage */

import java.util.Scanner;

public class JavaProgram


{
public static void main(String args[])
{
int mark[] = new int[5];
int i;
float sum=0;
float avg, perc;
Scanner scan = new Scanner(System.in);

System.out.print("Enter marks Obtained in 5 Subjects : ");


for(i=0; i<5; i++)
{
mark[i] = scan.nextInt();
sum = sum + mark[i];
}

avg = sum/5;
perc = (sum/500) * 100;

System.out.print("Average Marks = " +avg);

System.out.print("\nPercentage = " +perc+ "%");


}
}

When the above Java Program is compile and executed, it will produce the following output:

You might also like