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..

Answers were Sorted based on User's Feedback



take any 4 input numbers. like 2345.. wanted out put is All 16 combinations of the number 2345.. f..

Answer / 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

take any 4 input numbers. like 2345.. wanted out put is All 16 combinations of the number 2345.. f..

Answer / anitha

package com.boa.example.java;

public class NumberTest {

public void swapnum(int a,int b,int c,int d){

for(int x=0;x<=3;x++){
int t1=0;
int t2=0;
int t3=0;

if(x == 0){
t1= b;
t2=c;
t3=d;
}

if(x == 1){
t1= c;
t2=b;
t3=d;
}

if(x == 2){
t1= c;
t2=d;
t3=b;
}
if(x == 3){
t1= b;
t2=d;
t3=c;
}
System.out.println(a+""+t1+""+t2+""+t3 );
}
}

public static void main(String args[]){
int i=1;
int j=2;
int k=3;
int l =4;

NumberTest n = new NumberTest();
n.swapnum(i,j,k,l);
n.swapnum(j,k,l,i);
n.swapnum(k,l,j,i);
n.swapnum(l,k,j,i);
}
}
o/p-1234
1324
1342
1243
2341
2431
2413
2314
3421
3241
3214
3412
4321
4231
4213
4312

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More Core Java Interview Questions

In java, what is the difference between method overloading and method overriding?

0 Answers  


Where are the card layouts used?

0 Answers  


adapter class ?

2 Answers  


What is generics in java interview questions?

0 Answers  


Define array. Tell me about 2-D array.

0 Answers   Agilent,






Do I need java on my computer?

0 Answers  


What is singleton pattern?

0 Answers  


why to use transient variables when static variables can be used for Serialization

4 Answers  


Which collection allows duplicate values in java?

0 Answers  


explain me with a code snippet about the generation and handling of null point exceptions.

1 Answers  


Compare java and python.

0 Answers  


Can we call thread start () twice?

0 Answers  


Categories