Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Arrays in java:

A program that analyzes a set of numbers can be very useful. Create an Analysis application that prompts the user for numbers in the range 1 through 50, terminated by a sentinel, and then performs the following analysis on the numbers
Determine the average number
Determine the maximum number
Determine the range (maximum - minimum)
Displays a histogram that shows the numbers in each five-unit range.

--- Update ---

how do i go about solving this problem?
this is what i have so far:
import java.util.Scanner;

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

Scanner scan = new Scanner (System.in);
int array [] = new int[0];
int num;
System.out.println("Enter a number between 1 - 50 inclusive OR -1 if u wish to end");
array = num.nextInt();

//loop with sentinel value
while( num != -1)
array[0]++;

// maximum value
int maximum;
for( num=0; num<=50; num++){
if (maximum< array[num]){
maximum= array[num];
}
}

// minimum value
int minimum;
for (num=0; num >=50; num++){
if(minimum>array[num]){
minimum=array [num];
}
}

// average
int average;
int sum;
for(num=0; num<=50;num++){
sum=sum+array[num];
}
average = sum/50;

int range;
range = maximum-minimum;

}

}

2. ## Re: Arrays in java:

I am not sure, but I think your array holds no values in it. And you try to compare the number with the values within the array, which do not exist.
And besides that, array = num.nextInt(); gives error.

To get input from user, you should do this (using your variable names);

num = scan.nextInt();

Once you define an array (int array [] = new int[0]; ) you can't change its length. It seems you are trying to do that as well.

3. ## The Following User Says Thank You to beer-in-box For This Useful Post:

puny prince (February 14th, 2013)