Java Program to Find Total Marks and Percentage using 1D Array

«
»
This is a Java Program to Accept the Marks of a Student into a 1D Array and find Total Marks and Percentage. A one-dimensional array is, essentially, a list of like-typed variables.

Enter the number of subjects and then enter marks if students in all those subjects. Now we us for loop to calculate total marks of the student and hence divide it by the total number of subjects to get percentage marks.

Here is the source code of the Java Program to Accept the Marks of a Student into a 1D Array and find Total Marks and Percentage. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

advertisement
  1. import java.util.Scanner;
  2. public class Student_Marks
  3. {
  4.     public static void main(String[] args) 
  5.     {
  6.         int n, total = 0, percentage;
  7.         Scanner s = new Scanner(System.in);
  8.         System.out.print("Enter no. of subject:");
  9.         n = s.nextInt();
  10.         int marks[] = new int[n];
  11.         System.out.println("Enter marks out of 100:");
  12.         for(int i = 0; i < n; i++)
  13.         {
  14.             marks[i] = s.nextInt();
  15.             total = total + marks[i];
  16.         }
  17.         percentage = total / n;
  18.         System.out.println("Sum:"+total);
  19.         System.out.println("Percentage:"+percentage);
  20.     }
  21. }

Output:

$ javac Student_Marks.java
$ java Student_Marks
 
Enter no. of subject:5
Enter marks out of 100:
86
89
91
82
78
Sum:426
Percentage:85

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.