Well I would like to help you up to some extent that's why I'm going to tell you solution of this problem almost. You can try rest of the things as per your requirement.
public static void main(String[] args) {
try (Scanner in = new Scanner(System.in)) {
int iNum = in.nextInt();
int iRange = 3;// Fixed for now.
int iCount = 1;
int iIncrement = iRange / 2;
for (int i = iNum; i >= 0; i--) {
for (int k = 0; k < iCount; k++) {
for (int j = 0; j < iRange; j++) {
if (j == 0) {// Printing First Digit.
System.out.print(i + " - ");
} else if (j == iRange - 1) {// Printing Last Digit.
System.out.print(k + ";");
} else {
// Printing Rest of the Digits.
/**
* Edit this section to make this code generic for variable iRange.
*/
System.out.print((iNum - i - k) + " - ");
}
// System.out.print(i + " - " + j + " - " + k + " : ");
}
System.out.println();
}
iCount += iIncrement;
}
}
}
Output-:
5
5 - 0 - 0;
4 - 1 - 0;
4 - 0 - 1;
3 - 2 - 0;
3 - 1 - 1;
3 - 0 - 2;
2 - 3 - 0;
2 - 2 - 1;
2 - 1 - 2;
2 - 0 - 3;
1 - 4 - 0;
1 - 3 - 1;
1 - 2 - 2;
1 - 1 - 3;
1 - 0 - 4;
0 - 5 - 0;
0 - 4 - 1;
0 - 3 - 2;
0 - 2 - 3;
0 - 1 - 4;
0 - 0 - 5;
Description-: I have written this code for variable iNum
(the_specific_number) and fixed iRange
(length_of_the_array). While running this application it'll ask for iNum
to input manually and generate your required array of numbers.
If you want to make it generic for iRange
then you can update logic inside else
section.
} else {
// Printing Rest of the Digits.
/**
* Edit this section to make this code generic for variable iRange.
*/
System.out.print((iNum - i - k) + " - ");
}
You can use // System.out.print(i + " - " + j + " - " + k + " : ");
line to analyse values of i, j & K
in all the cases so that you can make some conclusion to write logic for variable range of iRange
.
I hope this would help you up to some extent. We can discuss further if you wish to do so. But it's always better to try your self before asking to some one else and if you have done something then share the work done while asking.