JAVA 728 Math combinations Write a program that prompts the
JAVA
*7.28 (Math: combinations) Write a program that prompts the user to enter 10 integers
and displays all combinations of picking two numbers from the 10.
Solution
import java.util.*;
class Combinations
{
public static void main (String[] args)
{
int[] num = new int[10];
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter 10 integers: \");
for (int i = 0; i < 10; i++)
num[i] = scan.nextInt(); //input 10 integer numbers
System.out.println(\"Combinations of two integers from 10 integers :\");
for (int i = 0; i < num.length; i++)
{
for (int j = 0; j < num.length; j++)
{
if (j != i) //if two numbers are not equal , make their combination
{
System.out.println(num[i] + \"--- \" + num[j] );
}
}
}
}
}
output:
