Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class arraychecknumber
- {
- public static void main(String[] args)
- {
- int[] previous = new int[4];
- Scanner scan = new Scanner(System.in);
- //boolean check = false;
- for (int i = 0; i < 5; i++) {//outer loop, looping 5 times to get 5 numbers from the user
- int num;
- System.out.println("Enter a number between 10 and 100:");
- num = scan.nextInt();
- int k;
- for (k = 0; k < i; k++) {// checking previous entries
- if (num == previous[k]) {
- System.out.println("Entered a duplicate number ");
- break;}
- }
- if (k == i)
- System.out.println("The number you entered: " + num);
- if (i < 4)
- previous[i]=num;
- }
- }
- }
Add Comment
Please, Sign In to add comment