Question:
my java program won't compile, help?
meaganicole
2011-12-02 16:45:26 UTC
hi,

My java program won't compile at all and I've tried everything to figure it out but still doesn't work:

import java.util.Scanner;
/* Design and build a program to enable a user to input an array of six integers, which represent the scores allocated by judges in an ice skating competition. Once all scores have been entered into the array, use it to calculate and output the average score. */

class iceSkaters
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

int[] scores = new int[6];
int count;
int overall = 0;

for (count = 0; count < 6; count++)
{
system.out.print("Please input the scores that have been allocated by the judges " + (count(+)1) ": ");
scores[count] = input.nextInt();
}

for (count = 0; count < 6; count--)
{
overall = overall + scores[count];
}

System.out.print("average = " + (overall/6.0));
}
}

The errors that it is giving me:

iceSkaters.java:16: illegal start of expression
system.out.print("Please input the scores that have been
allocated by the judges " + (count(+)1) ": ");

^
iceSkaters.java:16: ')' expected
system.out.print("Please input the scores that have been
allocated by the judges " + (count(+)1) ": ");

^
iceSkaters.java:16: ';' expected
system.out.print("Please input the scores that have been
allocated by the judges " + (count(+)1) ": ");

^
iceSkaters.java:16: not a statement
system.out.print("Please input the scores that have been
allocated by the judges " + (count(+)1) ": ");

^
iceSkaters.java:16: ';' expected
system.out.print("Please input the scores that have been
allocated by the judges " + (count(+)1) ": ");

^
5 errors

what can i do to resolve the issue?

thanks
Three answers:
♛ Nicolas ♛
2011-12-02 17:04:25 UTC
in the line :

system.out.print("Please input the scores that have been allocated by the judges " + (count(+)1) ": ");



i fixed the lower case S in System.out.println

I took out the parenthesis around the + and added a + after the 1) to make the new line

System.out.print ("Please input the scores that have been allocated by the judges " + (count + 1) + ": ");

other than that try using an array of doubles not ints.
swell and well to the MAX
2011-12-03 00:54:22 UTC
I have two things to say. One, I unfortunately didn't get the scores to display on one line. You seem like a very gifted person. Secondly, using a double would be more wise for this code for two main reasons. One, double can be used to replace an integer anyway, and second of all, when you type in the code for the average of the numbers, the average is going to be a double sometimes, so you can't imlement a possible double and an int in the same code for the same specific variable. You can do it with integers, but it would be a lot harder. Here's the code for you.



import java.util.Scanner;



public class iceskating {



public static void main(String[]args) {



double score1;

double score2;

double score3;

double score4;

double score5;

double score6;



Scanner input = new Scanner(System.in);



System.out.println("Enter the six scores of the iceskaters in the skating competition.");

score1=input.nextDouble();

score2=input.nextDouble();

score3=input.nextDouble();

score4=input.nextDouble();

score5=input.nextDouble();

score6=input.nextDouble();



System.out.println(score1);

System.out.println(score2);

System.out.println(score3);

System.out.println(score4);

System.out.println(score5);

System.out.println(score6);



System.out.println(score1 /6 +score2 /6 +score3 /6 +score4 /6 +score5 /6 + score6 /6 );



}

}
2011-12-03 00:55:47 UTC
I won't insult your intelligence by blatantly telling you how to change your code. Here's the basic Java lesson on why it won't compile so you understand what's going on in the future.



a + between a string and an integer will concatenate them together

"a" + 1

becomes

"a1"

1 + 1

becomes

2

"a" + (1 + 1) + "b"

becomes

"a2b"



And generally, anything underlined in red by your IDE is a syntax error.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...