Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.io.*;
- import java.util.*;
- class Enters {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- ArrayList<Integer> arr = new ArrayList<Integer>();
- try{
- System.out.println("Enter numbers:");
- int i;
- int j;
- while (true) {
- int count = 0;
- int input = scanner.nextInt();
- arr.add(input);
- for (int temp : arr) {
- if(temp == input){
- count++;
- }
- }
- if(count==2){
- System.out.print("The number is entered twice.");
- }
- else if(count>2){
- System.out.println("The number is entered more than 2 times.");
- }
- }
- }catch(Exception e) {
- // Block of code to handle errors(In this case it stops the program)
- System.out.println("End of the program!");
- }
- }
- }
Add Comment
Please, Sign In to add comment