take any 4 input numbers. like 2345.. wanted out put is All 16 combinations of the number 2345..
for example-
taking input as 4565
output-
5654
4556
4655..
Answer Posted / vvsatya.
package dv.java;
public class ItrateFourNumbers {
int i=1;int j=2;int k=3;int l=4;int temp=0;
public ItrateFourNumbers() {
}
void klSwap(){
temp=k;
k=l;
l=temp;
System.out.println(i+""+j+""+k+""+l);
}
void itrateFourNum(){
for (int m = 0; m <=3; m++) {
klSwap();
klSwap();
temp=j;
j=k;
k=l;
l=temp;
System.out.println(i+""+j+""+k+""+l);
klSwap();
temp=j;
j=l;
l=k;
k=temp;
System.out.println(i+""+j+""+k+""+l);
klSwap();
temp=k;
k=j;
j=l;
l=i;
i=temp;
System.out.println(" ");
}
}
public static void main(String[] args) {
ItrateFourNumbers ifn= new ItrateFourNumbers();
ifn.itrateFourNum();
}
}
| Is This Answer Correct ? | 3 Yes | 2 No |
Post New Answer View All Answers
From the two, which would be easier to write: synchronization code for ten threads or two threads?
Why map is used in java?
How do you use equal in java?
Why java is considered dynamic?
Can you achieve runtime polymorphism by data members?
Are private methods final?
Why is stringbuffer called mutable?
What are the differences between stringbuffer and stringbuilder?
What is Java Annotations?
What is data type example?
What is the purpose of the finally clause of a try-catch-finally statement in java programming?
why are there separate wait and sleep methods? : Java thread
What is a string token?
Which is the class in java?
How is garbage collection controlled?