Need JAVA help

Discussion in 'Programming General' started by nazyboy, Sep 27, 2012.

Need JAVA help
  1. Unread #1 - Sep 27, 2012 at 8:29 PM
  2. nazyboy
    Joined:
    Sep 26, 2011
    Posts:
    607
    Referrals:
    0
    Sythe Gold:
    2
    Discord Username:
    noahz#7323

    nazyboy Forum Addict

    Need JAVA help

    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
     
< Runescape Client | Help? >

Users viewing this thread
1 guest


 
 
Adblock breaks this site