0% found this document useful (0 votes)
35 views3 pages

Java Program

Uploaded by

Minder
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)
35 views3 pages

Java Program

Uploaded by

Minder
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/ 3

Here's a simple Java program for beginners to practice basic concepts like loops, conditionals, and

functions. This example program calculates the average of three exam scores and determines the grade.

### Java Program: Calculate Average and Determine Grade

```java

import java.util.Scanner;

public class GradeCalculator {

// Function to calculate the average of three scores

public static double calculateAverage(double score1, double score2, double score3) {

return (score1 + score2 + score3) / 3;

// Function to determine the grade based on the average score

public static String determineGrade(double average) {

if (average >= 90) {

return "A";

} else if (average >= 80) {

return "B";

} else if (average >= 70) {

return "C";

} else if (average >= 60) {

return "D";

} else {

return "F";

}
// Main method

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the first score: ");

double score1 = scanner.nextDouble();

System.out.print("Enter the second score: ");

double score2 = scanner.nextDouble();

System.out.print("Enter the third score: ");

double score3 = scanner.nextDouble();

double average = calculateAverage(score1, score2, score3);

String grade = determineGrade(average);

System.out.println("Average score: " + String.format("%.2f", average));

System.out.println("Grade: " + grade);

scanner.close();

```

### How It Works:

1. **calculateAverage**: This method takes three scores as input and returns their average.

2. **determineGrade**: This method takes the average score and determines the grade based on a
simple grading scale.
3. **main method**:

- Uses a `Scanner` object to read user input for three scores.

- Calculates the average.

- Determines and displays the grade.

### Practice Tasks:

1. Modify the grading scale to use a different system.

2. Add input validation to ensure the scores are between 0 and 100.

3. Extend the program to handle any number of scores using loops and arrays.

4. Implement a feature where the user can calculate grades for multiple students in one run.

You might also like