array dimension missing
807598May 25 2006 — edited May 25 2006Program wont compile. Keeps giving me an array dimension missing error. Anyone know why?
import java.util.*;
public class ExampleArray// Name of program
{
public static void main(String[]args)
{
//Declare variables
int thisMany,sum;
int[]theList=new int[]
//Initialize variables
thisMany=theList[0];
sum=0;
//Prepare code to accept keyboard input
Scanner keyboard=new Scanner(System.in);
//Print welcome message and save input
System.out.println("How many numbers will you enter?");
thisMany=keyboard.nextInt();
for(i=0;i<thisMany;i++)//loop that stores numbers until i gets to thisMany
{
System.out.println("Enter integer "+(i+1)+" :");
theList=keyboard.nextInt();
}
for(int i=0;i<thisMany;i++)//loop that calculates the sum of the numbers entered
{
sum=sum+theList[i];
}
System.out.println("The sum of the numbers is:"+sum);//Prints the sum of the numbers entered
for(int i=0;i<thisMany;i++)//loop that calculates and prints the percent of the sum for each number
{
System.out.println(theList[i]+" is "+(int)(((double)theList[i]/sum)*100+0.5)+" %of the sum");
}
}
}