1. Member Join Date
Feb 2011
Posts
12
Rep Power
0

## Help!

So, I have this program running almost perfectly. Requirement 8 is a little buggy tho. The unique values array is supposed to end up having all unique values in order without any empty elements between them. The empty elements should only be the last few elements. Any ideas what I need to change to make this run properly?

[My Code]
import java.util.Scanner;

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

//1. Declare a constant named MAX_SIZE and set to 10
final int MAX_SIZE = 10;

//2. Declare an array of ints with capacity MAX_SIZE
int[] values = new int [MAX_SIZE];

//3. Prompt and read for 10 values and store in array
for (int i = 0; i < values.length; i++)
{
System.out.println("Enter and integer: ");
values[i] = scan.nextInt();
}

//4. Calculate and print the minimum values stored
int min = values;

for (int i = 0; i < values.length; i++)
{
if (values[i] < min)
min = values[i];
}
System.out.println("The minimum value is: " + min);

//5. Calculate and print the maximum values stored
int max = values;

for (int i = 0; i < values.length; i++)
{
if (values[i] > max)
max = values[i];
}
System.out.println("The maximum value is: " + max);

//6. Calculate and print the sum of all values stored
int sum = 0;

for (int i = 0; i < values.length; i++)
{
sum += values[i];
}
System.out.println("The sum of all the values is: " + sum);

//7. Calculate and print the average value
double avg = 0;

for (int i = 0; i < values.length; i++)
{
avg = (double) sum / values.length;
}
System.out.println("The average value is: " + avg);

[HELP ME HERE]

//8.CALCULATE AND PRINT A LIST OF ALL THE VALUES AND THE NUMBER OF TIMES EACH OCCUR

int[] UniqueValues = new int [MAX_SIZE];
int[] times = new int [MAX_SIZE];
int count = 0;

for (int i = 0; i < values.length; i++)
{
boolean found = false;
for (int j = 0; j < UniqueValues.length && found == false; j++)
{
if (values[i] == UniqueValues[j])
{
times[j]++;
found = true;
}
}

if (found != true)
{
UniqueValues[i] = values[i];
times[i] = 1;
count++;
}
}

System.out.println("UniqueValues\t" + "Times occured");

for (int i = 0; i < UniqueValues.length; i++)
{
System.out.println("\t" + UniqueValues[i] + "\t\t" + times[i]);
}
}
}
[END CODE]
Last edited by huntersmommy030508; 04-28-2011 at 04:14 PM.  Reply With Quote

2. ## Please wrap your code in code tags
[code ]<-omit space
[/code]

Also, provide more information about what you want, and what you are unsure about. Finally, you probably should have posted this in the new to java section.  Reply With Quote

3. Member Join Date
Feb 2011
Posts
12
Rep Power
0

## I want my output to look like this...

if my original array is:
8
7
10
15
15
10
5
2
10
8

I want my UniqueValues[] array and my times[] array to look like this...

UniqueValues---------times
8------------------2
7------------------1
10-----------------3
15-----------------2
5------------------1
2------------------1
0------------------0
0------------------0
0------------------0
0------------------0
Last edited by huntersmommy030508; 04-28-2011 at 04:25 PM.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•