java - Largest palindrome product -


i've written program calculate largest palindrome product of 2 3 digit number. i've solved problem @ project euler, solving same in hackerrank fails test cases. wonder what's wrong.

input :

first line contains t denotes number of test cases. followed t lines, each containing integer, n.

constraints:

1≤t≤100

101101<n<1000000

public class solution {     static boolean ispalin ( int i){      int low = 0;         string = string.valueof(i);      int high = a.length() - 1;       while(low<high){        if(a.charat(low) == a.charat(high)){          low++;          high--;        }else{             return false;        }      }      return true; }  public static void main(string[] args) {     scanner in  = new scanner(system.in);     int noofcases = in.nextint();     int currmax = 0, result = 0;     int no_one, no_two;     int largest = -1;      for(int i=0; i<noofcases; i++){          currmax = in.nextint();          for(no_one = 100; no_one<=999; no_one++){             for(no_two = 101; no_two<=999; no_two++){                 result = no_one * no_two;                  if(ispalin(result)){                     if(result > largest && result < currmax )                         largest = result;                 }             }         }         system.out.println(largest);     } } 

you testing multiple cases, reset largest -1 @ start of program.

try adding largest=-1; start of loop on i.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -