- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to illustrate Total Marks and Percentage Calculation
We will demonstrate how total marks and Percentages are calculated using Java programs. The term total marks refer to the summation of all the available marks, while the term percentage refers to the number obtained by dividing the calculated marks by total marks and multiplying the resultant by 100.
percentage_of_marks = (obtained_marks/total_marks) × 100
Example 1
This is a Java program to demonstrate how total marks and percentages are calculated.
// Java Program to demonstrate how is Total marks and Percentages calculated import java.io.*; public class TotalMarks_Percent1 { public static void main(String[] args){ int n = 8, t_marks = 0; float percent; // creation of 1-D array to store marks int marks[] = { 69, 88, 77, 89, 98, 100, 57, 78 }; // calculation of total marks for (int j = 0; j < n; j++) { t_marks += marks[j]; } System.out.println("Total Marks is: " + t_marks); // calculate the percentage percent = (t_marks / (float)n); System.out.println("Total Percentage is: " + percent + "%"); } }
Output
Total Marks is: 656 Total Percentage is: 82.0%
In the above Java program, the total marks obtained by a student in 8 subjects and their percentage is being calculated. The obtained marks are stored in an array named marks [].
The total marks are calculated and stored in a variable named t_marks and their percentages are calculated and stored in a variable named percent.
Both values are further displayed on the console.
Example 2
This is a Java program to demonstrate the calculation of the total marks and percentage of five subjects taken as input from the user.
// Java program to compute the total marks and percentage of five subjects taken as input from the user import java.util.Scanner; class TotalMarks_Percent2{ public static void main(String args[]){ float FLAT, COA, Networking, Python, AI; double t_marks, percent; Scanner mk =new Scanner(System.in); // Take marks as input of 5 subjects from the user System.out.println("Input the marks of five subjects \n"); System.out.print("Enter marks of FLAT:"); FLAT = mk.nextFloat(); System.out.print("Enter marks of COA:"); COA = mk.nextFloat(); System.out.print("Enter marks of Networking:"); Networking = mk.nextFloat(); System.out.print("Enter marks of Python:"); Python = mk.nextFloat(); System.out.print("Enter marks of AI:"); AI = mk.nextFloat(); // Calculation of total marks and percentage obtained in 5 subjects t_marks = FLAT + COA + Networking + Python + AI; percent = (t_marks / 500.0) * 100; // display the results System.out.println("Total marks obtained in 5 different subjects ="+t_marks); System.out.println("Percentage obtained in these 5 subjects = "+percent); } }
Output
Input the marks of five subjects Enter marks of FLAT:98 Enter marks of COA:56 Enter marks of Networking:67 Enter marks of Python:89 Enter marks of AI:78 Total marks obtained in 5 different subjects =388.0 Percentage obtained in these 5 subjects = 77.60000000000001
In the above Java program, the marks obtained in 5 different subjects, namely FLAT, COA, Networking, Python, and AI are taken as input from the user.
The marks are taken as input from the user and are stored in variables of float data type. Further, the total marks obtained in these subjects are calculated by the addition of the marks of each subject and are stored in a variable named t_marks.
Finally, the program displays the total marks obtained in the stated subjects and their percentage.
This article threw light on two ways to calculate total marks and their percentage. The article began with a discussion of term percentage and total marks. The first method discusses the method without taking input from a user and in the second method, the value of marks is taken as input from a user and their sum and percent are calculated and displayed.