## Forum Stats

• 3,875,374 Users
• 2,266,908 Discussions

Discussions

# Array Help

Member Posts: 1 Green Ribbon
edited Sep 28, 2022 1:00PM

Hi everyone,

Here's the problem.

Write a program that declare an array element consisting of students’ test scores in the range 0 – 200. It should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100-124, 125-149, 150-174 and 175-200. (Note: assign the following scores to get the Frequency of the scores; 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189)

public class Group7_MidLabAct1_Problem1{

public static void main (String[]args) {

200,87,35,157,189};

String[][]output= {{"0-24\t\t"},

{"25-49\t\t"},

{"50-74\t\t"},

{"75-99\t\t"},

{"100-124\t\t"},

{"125-149\t\t"},

{"150-174\t\t"},

{"175-200\t\t"}};

for(int b=0;b<output.length;b++) {

Integer.parseInt(output[b][1]);}

output[0][1]=output[0][1]+1;

output[1][1]=output[1][1]+1;

output[2][1]=output[2][1]+1;

output[3][1]=output[3][1]+1;

output[4][1]=output[4][1]+1;

output[5][1]=output[5][1]+1;

output[6][1]=output[6][1]+1;

output[7][1]=output[7][1]+1;

}

for(int d=0;d<output.length;d++) {

for(int e=0;e<output[d].length;e++) {

System.out.print(output[d][e]);

}

System.out.println();

}

}

}

problem of the my code instead of having the number of frequency it have per range it just show how many it is by 0 and 1

sample output of the code:

0-24 01

25-49 011

50-74 0

75-99 0111111

100-124 01

125-149 0111

150-174 011111

175-200 011111111

it should be

0-24 1

25-49 2

50-74 0

75-99 6

100-124 1

125-149 3

150-174 5

175-200 8

Total: 26

• Posts: 1 Employee
edited Oct 24, 2022 4:18AM

`output[0][1]=output[0][1]+1;`

This is actually adding '1' to the string output[0][1] since output[0][1] is of type String. You need to

1. convert the output[0][1] to int
2. add 1 to the converted int value
3. convert the new value to string
4. assign output[0][1] to this string value

Same for other output[i][1] values.