gautam
BAN USER- 0of 0 votes
Answershow do we compare two objects in java.
- gautam in India| Report Duplicate | Flag | PURGE
Software Trainee Java
- 0 Answers JAVA
how do we compare two objects in java.
- gautam October 25, 2013| Flag | PURGE
import java.util.Scanner;
public class CompletePermutationTest{
public static void main(String [] args){
Scanner scn=new Scanner(System.in);
System.out.print("please enter your 4 alphabets\t");
char [] c1=new char[4];
int count1,count2,count3,count4;
count1=count2=count3=count4=0;
for(int i=0;i<c1.length;i++)
c1[i]=scn.next().trim().charAt(0);
System.out.println("here your alphabets that you enter\n");
for(int i=0;i<c1.length;i++)
System.out.print(c1[i]+"\t");
System.out.println("\n");
for(int i=0;i<c1.length;i++)
for(int j=0;j<c1.length;j++)
for(int k=0;k<c1.length;k++)
for(int l=0;l<c1.length;l++)
if(i==j&&j==k&&k==l){
System.out.print(c1[l]+"\t");
count1++;
}
else if(i==j&&j==k){
if(k!=l){
System.out.print(""+c1[k]+c1[l]+"\t");
count2++;
}
}
else if(i==j){
if(j!=k&&k!=l&&j!=l){
System.out.print(""+c1[j]+c1[k]+c1[l]+"\t");
count3++;
}
}
else if(i!=j&&i!=k&&i!=l&&j!=k&&j!=l&&k!=l){
System.out.print(""+c1[i]+c1[j]+c1[k]+c1[l]+"\t");
count4++;
}
System.out.println("\ntotal no of 1 string is\t"+count1+"\ntotal no of 2 String is\t"+count2);
System.out.println("total no of 3 String is\t"+count3+"\ntotal no of 4 String is\t"+count4);
System.out.println("total no of permutation is\t"+(count1+count2+count3+count4));
}
}
- gautam August 22, 2014