Explore BrainMass

Editing a Java Program

Please help with this java program (that is what I have so far its not displaying the medal count).

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

final int COUNTRIES = 7;

final int MEDALS = 3;

String[]country = { "CANADA", "CHINA","GERMANY", "COREA", "JAPAN", "RUSSIA" } ;

int[][]count = {{1,0,1},{1,1,0},{1,1,1,},{1,1,1},{1,0,0},{1,0,0}, {1,0,0}};

System.out.print( "Country Gold Silver Bronze Total" );

for(int i = 0; i < COUNTRIES ; i ++ ){

(System.out.printf("%15s", countries[i]);

int total = 0;
for(int j = 0; j < MEDALS ; j ++){

(System.out.printf("%8d" , counts [i][j]);

= total = total + counts[i][j];}

(System.out.printf("%d/n" , total);


Solution Preview

The code in this posting had several syntax errors and a few logic errors.

The original code declared two array variables "count" and "country" but then the code further in the program used the variables as "counts" and "countries". In Java the variable names have to match exactly. There were also a couple of places where extra "(" were added. Finally, the code to ...

Solution Summary

This solution shows how to correct several syntax errors in a Java program. It also shows how to use an initialization list for setting the initial values for an array. Both one and two dimensional arrays are used.