Posted by: helpjava11 June 2, 2014
NEW PUZZLE for Sajha Intellects Day 2
Login in to Rate this Post:     0       ?        
NAS bro: here is the code i wrote to find the ans...
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test{

public static void main(String[] args) {
int persistence=1;
int total=10;
List digits = new ArrayList();



for(int i=77;i<1000;i++){
total= persistence(i);
persistence++;
// System.out.println(total);
while( total>9)
{
persistence++;
total= persistence(total);
if(persistence==5){

System.out.println("found the persistence of 5: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" );
}
}

System.out.println("persistent "+persistence);
// System.out.println(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
System.out.println();
persistence=0;
}

}




public static int persistence(int i){
/*
* because we are using list and using modulus we will get the digits in reverse order.
* to get the digits in right order we need to insert into list again print.
*/
int multip =1;
List digits = new ArrayList();
while(i > 0) {
digits.add(i % 10);
i /= 10;
}
System.out.println(digits);

for (int j=0;j multip = multip * digits.get(j);

}
// System.out.println(multip);
return multip;
}
}
Read Full Discussion Thread for this article