Kali ini saya ingin membagikan tentang kombinasi angka pada pemrograman java.
Silahkan dicoba, . .
import java.util.Scanner;
public class Combinations {
public static void main(String[] iriahus) {
@SuppressWarnings("resource")
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number: ");
int num1 = s.nextByte();
System.out.print("Enter the second number: ");
int num2 = s.nextByte();
int count = 0;
System.out.println("\nThe combinations are: ");
for (int i = num1; i <= num2; i++) {
for (int j = num1; j <= num2; j++) {
if (i == j)
continue;
if (i > j)
continue;
System.out.println(i + " " + j + " ");
count++;
}
System.out.println();
}
System.out.println("The total number of all combination is " + count);
}
}
Semoga bermanfaat, . .
0 Response to "Kombinasi Angka"
Post a Comment