Code Snippets (with Comments)

public class StudentScores {

    public static void main(String[] args) {

        // Array of student names

        String[] students = {"Ashley", "Kevin", "Charlie", "Nicole"}; 

        // Corresponding array of scores

        int[] scores = {85, 92, 78, 90};

        // Display header

        System.out.println("📊 Student Scores");

        System.out.println("------------------");

        // Loop through arrays and display names with scores

        for (int i = 0; i < students.length; i++) {

            System.out.println(students[i] + ": " + scores[i] + "%");

        }

        // Calculate the average score

        int total = 0;

        for (int score : scores) {

            total += score;

        }

        double average = (double) total / scores.length;

        System.out.println("\nClass Average: " + average + "%");

    }

}

What the outcome will be once ran on Java. 




Comments

Popular posts from this blog

Java a Whole New World of Coding

Introduction to Algorithmic Design and Data Structures