0% found this document useful (0 votes)
2 views

Lab 2 Solution

The document contains a Java program that collects unique numbers from user input, ensuring they are between 10 and 100. It checks for duplicates and displays the valid unique numbers entered. The program uses an array to store the numbers and a loop to validate and display them.

Uploaded by

Saeedul Karim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab 2 Solution

The document contains a Java program that collects unique numbers from user input, ensuring they are between 10 and 100. It checks for duplicates and displays the valid unique numbers entered. The program uses an array to store the numbers and a loop to validate and display them.

Uploaded by

Saeedul Karim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 2 Solution

package uniquenumbers;

import java.util.Scanner;

/**
*
* @author abdurrahmanjalil
*/
public class UniqueNumbers {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

int numbers[] = new int[5];


int count = 0;
Scanner input = new Scanner(System.in);

while(count < numbers.length)


{

System.out.println("\nEnter a number: ");


int inputNumber = input.nextInt();

//validate input between 10 and 100


if(inputNumber >= 10 && inputNumber <= 100)
{
boolean isDuplicate = false;
for(int i = 0; i < count; i++)

if(inputNumber == numbers[i])
isDuplicate = true;

if(!isDuplicate)
{
numbers[count] = inputNumber;
count++;
}

else
System.out.println("This is a duplicate");

}else
System.out.println("The number must be between 10 and 100!");

//display numbers in array


for(int i = 0; i < count; i++)
System.out.printf("%d ", numbers[i]);

You might also like