Write a java program to print all the possible combinations of a three digit number without using arrays?
eg
123 =
321
231
213
132
312
I spent time and effort trying numerous ideas and was stymied.This day I cooked up the examples below code with does work.It’s definitely not very elegant.
int n1, n2, n3;
to get (n1 = YOU; n1 <= THREE OR MORE; n1++)
n2 = (6 — n1) / COUPLE OF + YOU;
n3 = SIX – n1 — n2;
Method.out.println(
Chain.format(
“%d%d%d”,
n1, n2, n3));
Method.out.println(
Chain.format(
“%d%d%d”,
n1, n3, n2));
effects:
132
123
231
213
321
312
+add
Light Impair makes a fantastic point.The code is definitely 2 images and 4 lines = A FEW lines connected with code.You may print most 6 combos with 6TH lines regarding code!!!
For THREE OR MORE digit number possible combo are
103=1000
(0-9) possible digits negotiated on 3 places.
For( we =0; i<1000; i++)
printing I
Some other nested loop example which will clearly presents combination concept
For(i=0; i<10; i++)
For(j=0; j<10; j++)
For(k=0; k<10; k++)
Printing i, j, e
sudo signal use rather than javacode, utilize your java skill…
Given some (distinct) digits, you’ll find only THREE OR MORE! = SIX permutations, so it’s not too difficult to simply brute-force the item.You’ve already listed available the SIX possibilities for “123”.
Leave a Reply
You must be logged in to post a comment.