Create a Java program that asks the user to enter four pairs
Solution
PairTest.java
import java.util.Scanner;
 public class PairTest {
  
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print(\"Enter four numbers all between 0 and 9: \");
        int pairCount = 1;
        int totalPair = 0;
        int a[] = new int[4];
        for(int i=0; i<4; i++){
            a[i] = scan.nextInt();
        }
        for(int i=0; i<4; i++){
            for(int j=i+1; j<4; j++){
                if(a[i] == a[j]){
                    pairCount++;
                   
                }
               
            }
            if(pairCount>2){
                totalPair = totalPair+pairCount/2;
                break;
            }
            else{
                totalPair = totalPair+pairCount/2;
                pairCount=1;
            }
        }
        System.out.println(\"There are \"+totalPair+\" pair\");
    }
}
Output:
Enter four numbers all between 0 and 9: 1 0 1 1
 There are 1 pair
Enter four numbers all between 0 and 9: 9 9 9 9
 There are 2 pair


