Java Program To Accept the Marks of a Student and Find the Total Marks and Percentage
Question
Java Program To Accept the Marks of a Student and Find the Total Marks and Percentage
Solution
Sure, here is a simple Java program that accepts the marks of a student, calculates the total marks and the percentage:
import java.util.Scanner;
public class StudentMarks {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int subjects = 5; // number of subjects
int marks[] = new int[subjects];
int total = 0;
// Accepting marks
System.out.println("Enter the marks of " + subjects + " subjects:");
for(int i=0; i<subjects; i++) {
marks[i] = input.nextInt();
total += marks[i];
}
// Calculating total marks and percentage
float percentage = (float)total / subjects;
System.out.println("Total Marks: " + total);
System.out.println("Percentage: " + percentage + "%");
input.close();
}
}
This program first accepts the marks of 5 subjects from the user. It then calculates the total marks by adding all the marks together. The percentage is calculated by dividing the total marks by the number of subjects. Finally, it prints out the total marks and the percentage.
Similar Questions
using the while loop, and scenner draft a java code that grades students when they enter makes it grades it with A,B+,B,C,C+ and F grades
Write a program to write data into binary file marks.dat anddisplay the records of students who scored more than 95marks.
Enter the student details using constructors with arguments. Then find the total marks of each student. If it is greater than 500 print pass ,else print fail.
evelop a Java program that calculates the average of three floating-pointnumbers and displays a grade based on the average.
Marks scored by 104 students of a college in the mid-term exam given below. Draw histogram. Marks No. of students 0-24 12 24-40 16 40-48 24 48-68 40 68-80 12
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.