Printing All Possible Combinations of a 3 Digit Number Java Program

Printing All Possible Combinations of a 3 Digit Number Java Program:

Logic:

  • We have to write 3 for loops and need to ensure all three for loops variable does not have same value.
  • Then we can take and print the input array with the three for loop variables to get all different possibles.

Program:

package in.javadomain;

public class PossibleCombinations {

	public static void main(String[] args) {
		int[] input = { 1, 4, 3 };

		for (int x = 0; x < 3; x++) {
			for (int y = 0; y < 3; y++) {
				for (int z = 0; z < 3; z++) {

					if (x != y && y != z && z != x) {
						System.out.println(input[x] + "" + input[y] + ""
								+ input[z]);
					}
				}
			}
		}

	}

}

 

Output:

143
134
413
431
314
341

 

Recommended Books:

3,565 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *