deng_cen 19 Newbie Poster

try this function:
package com.Thread;
public class DigProd {
public static void main(String args[]) {
long a = 123456789;
long ai = DigProdIterative(a);
System.out.println("Digital Product of a: " + ai);
long ar = Recursive(a);
System.out.println("Digital Product of a: " + ar);
}

public static long doNumRecursive(long a){
long first,y=1;
String str = String.valueOf(a);
if(str.length()==1){
return a;
}
for (int i = 0; i < str.length(); i++) {
int b = str.charAt(i);
b = b - 48; // for ascii code
if (b == 0) {
continue;
} else {
first = str.charAt(i);
first = first - 48;
y = y * first;
}
}
return y;
}

public static long Recursive(long result){
String str = String.valueOf(result);
if(str.length()==1){
System.out.print(result + "\n");
return result;
}else{
System.out.print(result + " --> ");
result=doNumRecursive(result);
str = String.valueOf(result);
if(str.length()==1){
System.out.print(result + "\n");
return result;
}else{
result = Recursive(result);
return result;
}
}
}

public static long DigProdIterative(long a) {
String str = String.valueOf(a);
int first = 1;
long y = a;
while (str.length() != 1) {
str = String.valueOf(y);
if (str.length() == 1) {
System.out.print(y + "\n");
} else {
System.out.print(y + " --> ");
}
y = …