Computer Science, asked by jjmr15, 9 months ago

Write a program to accept name and total marks of N number of students in two single subscript array name[] and totalmarks[].

Accept a name from the user and display the total marks stored in the array.

this is for java and pls do by scanner class

Answers

Answered by LiteracyEducation
0

Explanation:

Menu

Java Program to Accept the Marks of a Student into a 1D Array and find Total Marks and Percentage

« Prev

Next »

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

import java.util.Scanner;public class Student_Marks{ public static void main(String[] args) { int n, total = 0, percentage; Scanner s = new Scanner(System.in); System.out.print("Enter no. of subject:"); n = s.nextInt(); int marks[] = new int[n]; System.out.println("Enter marks out of 100:"); for(int i = 0; i < n; i++) { marks[i] = s.nextInt(); total = total + marks[i]; } percentage = total / n; System.out.println("Sum:"+total); System.out.println("Percentage:"+percentage); }}

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

Similar questions