my other program class is my one dimensional array
/** this is the main objective:
* One dimensional array to set up the amount of numbers and return the average.
* Use a one-dimensional array to solve the
*following problem: Write an application
*that inputs five numbers, each between 10
*and 100, inclusive. As each number is read,
*display it only if it's not a duplicate of a
*number already read. Provide for the
*"worst case" in which all five numbers are
*different. Use the smallest possible array to
*solve this problem. Display the complete set
*of unique values input after the user enters
*each new value.Use a GUI with a text field to enter each
*value and a text area to display the unique values.
basically my code should be displaying a non duplicate array to the user
after he enters 5 numbers in a one dimensional array. the numbers each between 10 and 100 inclusively
i think i need a binary search or a search, then maybe 2 loops
* @author
* @version 03/8/2012
*/
/**
* One dimensional array to set up
* the amount of numbers and return the average.
*
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.util.Scanner; //import
public class UniqueDimensionalArrays{
int [] array = new int [5];
// create 5 elements in a one dimensional array program
Scanner keyboard = new Scanner(System.in);
int inputNumber = 1; //to show the input digit from a person
//create variables
int arrayPosition = 0; // to add array position
{
System.out.println(" Enter unique 5 digits ? 10 to max 100: "); //display message box asking a user to start to add numbers to the program
{
while (array[arrayPosition] == 0)
{ // start bracket
boolean insideArray = false; //digit to tell if input number is store in array
inputNumber = keyboard.nextInt(); //input found on keyboard for input numbers
if ((inputNumber > 9) && (inputNumber < 101)) // the numbers must be 10-100 so user will not go over the numbers
{
for (int existCount = 0; (existCount < array.length); existCount++) //for loop for second time ti display unique digits
{ //start the for loop test to see if digits exist
if (array[existCount] == inputNumber) //array # equals input #
{//start if loop
insideArray = true; // digit from user exist on the array
} //end if loop
} // end for loop if input digits is in the array
//display message box for unique numbers
System.out.println("The Unique digits are: ");
if (insideArray == false) //if inside array number is not correct
{
array[arrayPosition] = inputNumber;
}
else
{ //start else loop
System.out.println(" Incorrect Number, already contain that number ");
}//end else loop
}
else //orint error and goes to next input number
{ //start else
System.out.println(" Not correct, choose numbers from 10 - 100 ? ");
} //end else
//print all the numbers in an array
//the for loop will print array elements on the screen
System.out.println(" The Digits in the Array are : "); //print message to user before numbers shows up
for (arrayPosition = 0; arrayPosition < array.length; arrayPosition++)
{
System.out.print(array[arrayPosition] + " ");
}
System.out.println ("\n"); //print empty line
}
}}}