# Statistics V2 Java Exercise - Java Programming Course

### Example Code

``````import java.util.*;
public class Main
{
public static void main(String[] args)
{
float[] numbers = new float[1000];
int count = 0;

float max = 0.0f, min = 0.0f, total = 0.0f, searchNumber = 0.0f;
boolean found;

int option = 0;
do
{
System.out.println("2. Show");
System.out.println("3. Search");
System.out.println("4. Statistics");
System.out.println("5. Exit");

option = Integer.parseInt(new Scanner(System.in).nextLine());
if (option != 5)
{
switch (option)
{

System.out.println("Enter a number: ");
numbers[count] = Float.parseFloat(new Scanner(System.in).nextLine());

max = numbers[count];
min = numbers[count];

total += numbers[count];

count++;

if (max < numbers[count])
{
max = numbers[count];
}

if (min > numbers[count])
{
min = numbers[count];
}

break;
case 2: // Show

for (int i = 0; i < count; i++)
{
System.out.printf("%1\$s " + "\r\n", numbers[i]);
}

break;
case 3: // Search

System.out.println("Enter a number for search: ");
searchNumber = Float.parseFloat(new Scanner(System.in).nextLine());

for (int i = 0; i < count; i++)
{
if (numbers[i] == searchNumber)
{
found = true;
}
}

if (found)
{
System.out.printf("Number %1\$s found a amount of %2\$s " + "\r\n", numbers[i]);
}
else
{
found = false;
}

break;
case 4: // Statistics

System.out.printf("Total data: %1\$s" + "\r\n", count + 1);
System.out.printf("Sum: %1\$s" + "\r\n", total);
System.out.printf("Average: %1\$s" + "\r\n", total / (count + 1));
System.out.printf("Min number: %1\$s" + "\r\n", min);
System.out.printf("Max number: %1\$s" + "\r\n", max);

break;
default:

System.out.println("Error, option 1-5");
break;
}
}
} while (option != 5);
}
}``````