Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package NestedLoops;
- import java.util.Scanner;
- public class P03Combinations {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- int countCombinations = 0;
- for (int x1 = 0; x1 <= number; x1++) {
- for (int x2 = 0; x2 <= number; x2++) {
- for (int x3 = 0; x3 <= number; x3++) {
- int currentCombination = x1 + x2 + x3;
- if (currentCombination == number){
- countCombinations++;
- }
- }
- }
- }
- System.out.println(countCombinations);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement