Need help with my JAVA homework ASAP Thx Create a Java progr
Need help with my JAVA homework. ASAP. Thx
Create a Java program that asks the user to enter four numbers between 0-9, then checks to see how many pairs of numbers there are (in any order). There can be 0 pairs, 1 pair, or 2 pairs. Once a number is assigned to a pair, it cannot be used to form a different pair. For example: If the user enters 0 10 1 the output would be 2 pair. If the user enters 9 9 5 5 the output would be 2 pair If the user enters 9 9 9 9 the output would be 2 pair If the user enters 9 9 9 5 the output would be 1 pair If the user enters 3 2 13 the output would be 1 pair If the user enters 5 6 7 1 the output would be 0 pair If the user enters 10 11 the output would be 1 pair. See below for a sample of runs. Prove a printout of properly formatted source code (your entire Java program). Provide 4 example outputs/test case: showing all four possibilities - no pairs, 1 pair, 2 pairs and a case with 1 pair when three numbers match.Solution
import java.util.Scanner;
public class Pair
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int p2=0,p3=0;
int a,b,c,d;
System.out.println(\"\ enter a b c and d:\");
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
d=s.nextInt();
if(a==b)
{
p2++;
if(c==d)p2++;
}
if(b==c)
{
p2++;
if(a==d)
p2+;
}
if(a==c)
{
p2++;
if(b==d)p2++;
}
if(a==b&&b==c)
p3++;
if(b==c&&c==d)p3++;
if(a==c&&c==d)p3++;
System.out.println(p2+\" two element pairs \");
System.out.println(p3+\" three element pairs\");
}
}
import java.util.Scanner;
 public class Pair
 {
 public static void main(String args[])
 {
 Scanner s=new Scanner(System.in);
 int p2=0,p3=0;
 int a,b,c,d;
 System.out.println(\"\  enter a b c and d:\");
 a=s.nextInt();
 b=s.nextInt();
 c=s.nextInt();
 d=s.nextInt();
 if(a==b)
 {
 p2++;
 if(c==d)p2++;
 }
 if(b==c)
 {
 p2++;
 if(a==d)
 p2+;
 }
 if(a==c)
 {
 p2++;
 if(b==d)p2++;
 }
 if(a==b&&b==c)
 p3++;
 if(b==c&&c==d)p3++;
 if(a==c&&c==d)p3++;
 System.out.println(p2+\" two element pairs \");
 System.out.println(p3+\" three element pairs\");
 }
 }


