0

Hello guys, I'm trying to make a list of students grade using array. My question is, how am I going to do this?

OUTPUT:
Lea 94
Morgan 85
Jenny 92
Harold 75

I've tried a bit to program, please do check my code.

public class StudentScoreArray {
    public static void main(String[] args){

        int[] scores = { 94, 85, 92, 75 };
        String[] students = { "Lea", "Morgan", "Jenny", "Harold" };

        for( int i = 0; i < scores.length; i++ ){
            //System.out.print(scores[i] + " ");
        for( int j = 0; j < students.length; j++ ){
                System.out.print(students[j] + " " + scores[i] + " ");
        }   
        System.out.println("");
        }
    }
}

But I got this:

Lea 94 Morgan 94 Jenny 94 Harold 94
Lea 85 Morgan 85 Jenny 85 Harold 85
Lea 92 Morgan 92 Jenny 92 Harold 92
Lea 75 Morgan 75 Jenny 75 Harold 75

Any help would be appreciated :)

Edited by bettybarnes

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Vs5193
0

I changed it to

public class StudentScoreArray {
    public static void main(String[] args){

        int[] scores = { 96, 85, 99, 75 };
        String[] students = { "Rizzi", "Ria", "Jho", "Anne" };


            //System.out.print(scores[i] + " ");
        for( int j = 0; j < 4; j++ ){
            for( int i = 0; i < 1; i++ ){
                System.out.print(students[j] + " " + scores[j] + " ");
        }   
        System.out.println("");
        }
    }
}

but i couldn't make it to display each scores.

Edited by bettybarnes

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.