nazyboy
Forum Addict
hi guys,
i need some help on my computer science homework. We need to make a program that finds the persistence of a number, the number of times a number need to be multiplied by its own digits to become a single digit.
EXAMPLE: the number 715 has a persistence of 3
7*1*5=35 3*5=15 1*5=5
the number 27 has a persistence of 2
2*7=14 1*4=4
HERE IS MY CODE SO FAR:
public static void persistenceofanumber()
{
Scanner keyboard = new Scanner(System.in);
int num=keyboard.nextInt();
String s;
s=""+num;
while(s.length()>1)
{
int a=((s.charAt(0))-48)*((s.charAt(1))-48)*((s.charAt(2))-48);
s=""+a;
System.out.println(a);
}
}
WHAT I NEED HELP WITH: I need to make this work for any number (not just a 3 digit number), I need it to print out the persistence (not just the numbers themselves)
ANY HELP IS MUCH APPRECIATED
i need some help on my computer science homework. We need to make a program that finds the persistence of a number, the number of times a number need to be multiplied by its own digits to become a single digit.
EXAMPLE: the number 715 has a persistence of 3
7*1*5=35 3*5=15 1*5=5
the number 27 has a persistence of 2
2*7=14 1*4=4
HERE IS MY CODE SO FAR:
public static void persistenceofanumber()
{
Scanner keyboard = new Scanner(System.in);
int num=keyboard.nextInt();
String s;
s=""+num;
while(s.length()>1)
{
int a=((s.charAt(0))-48)*((s.charAt(1))-48)*((s.charAt(2))-48);
s=""+a;
System.out.println(a);
}
}
WHAT I NEED HELP WITH: I need to make this work for any number (not just a 3 digit number), I need it to print out the persistence (not just the numbers themselves)
ANY HELP IS MUCH APPRECIATED

