Untitled a guest Dec 31st, 2014 518 Never a guest518Never

Not a member of Pastebin yet? Sign Up , it unlocks many cool features!

rawdownloadcloneembedreportprint Java 1.14 KB import java.util.ArrayList ; public class Project004_LargestPalendromeProject { public static void main ( String args [ ] ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 999 ; i >= 0 ; i -- ) { for ( int j = 999 ; j >= i ; j -- ) { if ( isPalendrome ( i * j ) ) { list. add ( i * j ) ; break ; } } } int highest = getHighest ( list ) ; System . out . println ( highest ) ; } /* Turnes the number into string, compares it to the string's reverse, then returns accordingly */ public static boolean isPalendrome ( int number ) { String str = Integer . toString ( number ) ; char [ ] temp = str. toCharArray ( ) ; char [ ] ch2 = str. toCharArray ( ) ; for ( int i = temp. length - 1 ; i >= 0 ; i -- ) ch2 [ i ] = temp [ ( temp. length - 1 ) - i ] ; String str2 = new String ( ) ; for ( Character ch : ch2 ) { str2 += ch ; } if ( str. equals ( str2 ) ) return true ; return false ; } public static int getHighest ( ArrayList < Integer > list ) { int highest = list. get ( 0 ) ; for ( Integer temp : list ) if ( temp > highest ) highest = temp ; return highest ; } }

RAW Paste Data

import java.util.ArrayList; public class Project004_LargestPalendromeProject { public static void main(String args[]) { ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 999; i >= 0; i--) { for (int j = 999; j >= i; j--) { if (isPalendrome(i*j)) { list.add(i*j); break; } } } int highest = getHighest(list); System.out.println(highest); } /* Turnes the number into string, compares it to the string's reverse, then returns accordingly */ public static boolean isPalendrome(int number) { String str = Integer.toString(number); char[] temp = str.toCharArray(); char[] ch2 = str.toCharArray(); for (int i = temp.length-1; i >= 0; i--) ch2[i] = temp[(temp.length-1)-i]; String str2 = new String(); for (Character ch: ch2) { str2+= ch; } if (str.equals(str2)) return true; return false; } public static int getHighest(ArrayList<Integer> list) { int highest = list.get(0); for (Integer temp: list) if (temp > highest) highest = temp; return highest; } }