/* FirstNumberDup.java
CS 111A Solution to In-class exercise 4.5
Determine if there are duplicates of the first number in a series
by Craig Persiko
*/
import java.util.Scanner;
public class FirstNumberDup
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
double[] nums = new double[10];
boolean dup = false;
System.out.println("Please enter 10 numbers:");
for(int i=0; i<10; i++)
nums[i] = scan.nextDouble();
for(int j=1; j<10 && !dup; j++) // starting with element 1
if(nums[0] == nums[j])
dup = true;
if(dup)
System.out.println("Yes, the " + nums[0] + " is duplicated");
else
System.out.println("No, the " + nums[0] + " is not duplicated");
}
}
/* Sample Output:
Please enter 10 numbers:
5 4 3 2 1 5 6 7 8 9
Yes, the 5 is duplicated
Please enter 10 numbers:
4 3 2 1 2 3 5 6 7 8
No, the 4 is not duplicated
*/
syntax highlighted by Code2HTML, v. 0.9