Project Euler – Problem 52

Problem 52:
It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.

class runner
{	
	public static boolean matchCharacters(String x, String y){
		if(x.length() != y.length()) return false;
		boolean[] y1 = new boolean[x.length()];
 
		for(int i=0;i<y1.length;i++){
			boolean found = false;
			for(int j=0;j<y1.length; j++){
				if(!y1[j] && x.charAt(i) == y.charAt(j)){
					found = true;
					y1[j] = true;
					break;
				}
			}
			if(!found) return false;
		}
 
		return true;
	}
 
	public static void main (String[] args) throws java.lang.Exception
	{
		long time = System.currentTimeMillis();
 
		int n=2;
		while(true){
			String str_n = ""+n;
			boolean found = true;
			for(int i=2;i<7;i++){
				if(!matchCharacters(str_n, ""+(i*n))){
					found = false;
					break;
				}
			}
			if(found) break;
			n++;
		}
		System.out.println("n:"+n);
		System.out.println("time: "+(System.currentTimeMillis() - time));
	}
}