class CircularPrime{ public static void main(String args[]){ int Number1=0,Number1_noZero=0; int Number2=0,Number2_noZero=0; boolean answer; try{// if the user does not enter a number as an argument, catch the error and let the user know what the error is. //it is better because the error generated by the compiler could be hard to understand by the users who do not know about the code Number1=Integer.parseInt(args[0]); Number2=Integer.parseInt(args[1]); }catch(Exception e){ System.out.println("Please give two numbers as arguments"); System.exit(0); } System.out.println("Numbers entered are "+Number1+", "+Number2); //get the answer from the function answer=Test_Permutation(Number1,Number2); if(answer) System.out.println("\nYES, Numbers "+Number1+" and "+Number2+" are permutations of each other"); else System.out.println("\nNO, Numbers "+Number1+" and "+Number2+" are NOT permutations of each other"); } //checks if two number are permutations of each other //we count the occurences of each of the digits and then see if they are same or not. public static boolean Test_Permutation(int number1,int number2){ int one=0,two=0,three=0,four=0,five=0,six=0,seven=0,eight=0,nine=0; int radix=0; while(number1>0){ //find each digit of number1 count them radix=number1%10; //get the last digit number1=number1/10; //remove the last digit //don't count zeros as they can be manipulated if(radix==1)one++; else if(radix==2)two++; else if(radix==3)three++; else if(radix==4)four++; else if(radix==5)five++; else if(radix==6)six++; else if(radix==7)seven++; else if(radix==8)eight++; else if(radix==9)nine++; } //now find the digits in second number and subtract from count while(number2>0){ radix=number2%10;//get the last digit number2=number2/10;//remove the last digit if(radix==1)one--; else if(radix==2)two--; else if(radix==3)three--; else if(radix==4)four--; else if(radix==5)five--; else if(radix==6)six--; else if(radix==7)seven--; else if(radix==8)eight--; else if(radix==9)nine--; } if(one==0&&two==0&three==0&&four==0&&five==0&six==0&&seven==0&&eight==0&&nine==0) return true; //The counts matched. return true else return false; } }