Answers
Answer:
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args) {
int num[]=new int[5]; //array num of size 5
int temp=0,count,k=0;
Scanner s=new Scanner(System.in);
for(int i=0;i<5;i++) //this loop will make sure to enter 5 numbers each of which is b/w 10 and 100
{
count=0; //this is to increment if duplicate is found
System.out.print("Enter number:");
temp=s.nextInt();
while(temp<10 || temp>100){ //this loop will take care to enter element b/w 10 and 100
System.out.println("number should be b/w 10 and 100");
System.out.print("Enter number:");
temp=s.nextInt();
}
for(int j=0;j<k;j++) //comparing input to elements in array
{
if(temp==num[j])
{
count++;
System.out.print(temp+" has already been entered ");
}
}
if(count==0)
{
num[k]=temp; //input is stored into array only if no duplicate is foundd
k++; //k is used for indicating number of values stored in to array
}
for(int l=0;l<k;l++)
{
System.out.print(num[l]+" "); //this is for printing elements
}
System.out.println();
}
}
}
OUTPUT:
you could see here it increments value of k only if it is between 10 and 100 such that values entered less than 10 and greater than 100 are invalid.