Results 1 to 14 of 14
  1. #1
    vikramvvs is offline Member
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default print n number of armstrong numbers

    Hi Guyz

    Please can you help me where I am doing mistake to print the numbers of Armstromg numbers requested.

    import java.util.Scanner;
    public class ArmStrongNumber {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int x, y, z=0, temp, temp1=1;
    Scanner in = new Scanner(System.in);
    System.out.println("Enter the number of Armstrong numbers to be printed");
    x=in.nextInt();

    for(int count=1; count<=x;)
    // while(x==count)

    {
    temp=temp1;
    while(temp!=0)
    {
    y=temp%10;
    z=z+(y*y*y);
    temp=temp/10;
    }
    if(temp1==z)
    {
    System.out.println(temp1);
    count++;
    }
    temp1++;
    }

    in.close();

    }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: print n number of armstrong numbers

    When posting code, please use the code tags to preserve formatting.

    What is the problem? What does this code do? Where are you stuck?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    vikramvvs is offline Member
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default Re: print n number of armstrong numbers

    If the user asked to print the first 3 Armstrong numbers the program should generate the numbers.
    but its not printing

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: print n number of armstrong numbers

    Why isn't it printing? Have you tried stepping through this with a debugger, or at least adding some print statements to figure out when the program's execution differs from your expectations?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    vikramvvs is offline Member
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default Re: print n number of armstrong numbers

    how to preserve the formatting, I couldn't find the option

  6. #6
    vikramvvs is offline Member
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default Re: print n number of armstrong numbers

    yes I have tried in several ways. but I couldn't figure it out where I am doing silly mistake

    Please help me

  7. #7
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default Re: print n number of armstrong numbers

    I used your code to print 3 Armstrong numbers. It work but it needs a very fast cpu because it printed the second and the third number about 30 seconds after the firts number...

    The first number was: 1
    The second was: -1318169390
    The third was: -1206399854

  8. #8
    vikramvvs is offline Member
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default Re: print n number of armstrong numbers

    But it should print 1, 153, 370

  9. #9
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: print n number of armstrong numbers

    Quote Originally Posted by TheCazziator33 View Post
    I used your code to print 3 Armstrong numbers. It work but it needs a very fast cpu because it printed the second and the third number about 30 seconds after the firts number...

    The first number was: 1
    The second was: -1318169390
    The third was: -1206399854
    Like I said in the other thread, please stop guessing. Those aren't the intended output. Please be *sure* about what you're posting when trying to provide an answer.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: print n number of armstrong numbers

    Quote Originally Posted by vikramvvs View Post
    yes I have tried in several ways. but I couldn't figure it out where I am doing silly mistake

    Please help me
    Have you stepped through this with a debugger, or at least added some print statements, to figure out when the program's execution differs from your expectations? Where does it start to differ?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default Re: print n number of armstrong numbers

    Quote Originally Posted by KevinWorkman View Post
    Like I said in the other thread, please stop guessing. Those aren't the intended output. Please be *sure* about what you're posting when trying to provide an answer.
    He asked why it's not printing numbers, i answered that's because it takes a bit (i'm printing five numbers from about 5 minutes). Then if the numbers are wrong, there's an error in the code but it's another problem...
    Last edited by TheCazziator33; 03-27-2014 at 07:38 PM.

  12. #12
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: print n number of armstrong numbers

    Quote Originally Posted by TheCazziator33 View Post
    He asked why it's not printing numbers, i answered that's because it takes a bit (i'm printing five numbers from about 5 minutes). Then if the numbers are wrong, there's an error in the code but it's another problem...
    It's the *only* problem. Your replies don't make a lot of sense, and they're just confusing at best. That can be pretty frustrating in a technical forum, which is why I'm asking you -nicely- to be more careful with your answers.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  13. #13
    vikramvvs is offline Member
    Join Date
    Mar 2014
    Posts
    6
    Rep Power
    0

    Default Re: print n number of armstrong numbers

    Quote Originally Posted by KevinWorkman View Post
    Have you stepped through this with a debugger, or at least added some print statements, to figure out when the program's execution differs from your expectations? Where does it start to differ?
    I have not tried in that way , but I can say its executing but the results are not as expected.
    the sum of cubes of each digit should be equal to that number
    Ex: 1^3 + 5^3 + 3^3 =

  14. #14
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: print n number of armstrong numbers

    Quote Originally Posted by vikramvvs View Post
    I have not tried in that way , but I can say its executing but the results are not as expected.
    the sum of cubes of each digit should be equal to that number
    Ex: 1^3 + 5^3 + 3^3 =
    Right, so now it's time to debug the program. Have you tried adding print statements to check the value of each variable as the program executes? Try to isolate where the program stops doing what you expect it to do.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Java: Armstrong Numbers ?
    By mazzer07 in forum New To Java
    Replies: 4
    Last Post: 11-06-2013, 03:54 PM
  2. Replies: 8
    Last Post: 01-21-2012, 02:14 AM
  3. Replies: 12
    Last Post: 03-28-2011, 10:30 PM
  4. Replies: 7
    Last Post: 08-13-2010, 08:02 PM
  5. Prime Number - System print all the prime numbers ...
    By pinkdreammsss in forum New To Java
    Replies: 20
    Last Post: 04-26-2009, 02:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •