vitalii_hrushyn
7/28/2016 - 8:40 PM

palindrom

palindrom

package com.gmail.vhrushyn;

public class main {

	public static void main(String[] args) {
		
		int n = 0;
		int p = 0;
		int l = 0;
		int m = 0;
				
		for (int i = 1; i < 1000; i++) {
			for (int j = 1; j < 1000; j++) {
				n = i * j;
	
				// following short construction 'int to array int' was found in Internet
				String s = Integer.toString(n);
				int[] a = new int[s.length()];
				for (int k = 0; k < s.length(); k++)
				{
				    a[k] = s.charAt(k) - '0';
				}			
				if (isPal(a)) {
					if ( n > p) {		
						p = n;
						l = i;
						m = j;
					}
					
				}											
			}
		}	
		System.out.println("the largest palindrom of three digits number is " + p+" ("+l+" * "+m+")");	
}
	static boolean isPal(int[] a) {
		boolean b = false;
	 for (int i = 0; i < (a.length / 2); i++) {
		 if (a[i] == a[(a.length - 1) - i]) {
			 b = true;
		 }
		 else {
			b = false;
			return b;
		 }		 
	 }
	 return b;		
	}
}