Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

array dimension missing

807598May 25 2006 — edited May 25 2006
Program 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");
}

}
}

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 22 2006
Added on May 25 2006
2 comments
1,042 views