Purchase Solution

Editing a Java Program

Not what you're looking for?

Ask Custom Question

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);

}
}.

Purchase this Solution

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.

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 ...

Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Networking Questions

This quiz consists of some basic networking questions.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.