Results 1 to 11 of 11
  1. #1
    RichardYang is offline Member
    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Default Problem with integers

    hi
    i have a similar question regarding to this matter
    im having problem getting the odd integers printed out
    any suggestions?
    thank you.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,840
    Rep Power
    5

    Default Re: Adding odd numbers

    don't hijack someone else's thread. Create your own, provide as much information as you can give (especially code you have and an exception stacktrace you may be getting) and if you must link to an existing thread that demonstrates what you are talking about.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    kmlam585 is offline Member
    Join Date
    Feb 2012
    Posts
    6
    Rep Power
    0

    Default Re: Adding odd numbers

    Quote Originally Posted by RichardYang View Post
    hi
    i have a similar question regarding to this matter
    im having problem getting the odd integers printed out
    any suggestions?
    thank you.
    If you just need to print out the number to the console, in my example you would just do this:

    Java Code:
    import acm.program.*;
     
    public class AddOddInts extends ConsoleProgram {
     
        public void run() {
            int n = readInt("Enter a positive integer: ");
            int total = 0;
            for (int i = 1; i <= 2 * n - 1; i++) {
                if (i % 2 != 0) {
                    total += i;
                    //println(i + " Odd " + total);
                }
            }
            // This will print out the odd numbers to the console
            System.out.println(total);
            //println(total);
        }
    }

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Adding odd numbers

    I know you're trying to be helpful but even though this is your thread, please don't encourage bad behavior. IMO, this thread should be closed.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,920
    Rep Power
    19

    Default Re: Problem with integers

    Moved to their own thread.
    Of course, I've now lost the other one, but hopefully it won't get resurrected!
    Zombie threads are scary things, what with their insatiable appetite for brains.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,840
    Rep Power
    5

    Default Re: Problem with integers

    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,920
    Rep Power
    19

    Default Re: Problem with integers

    Thank you.
    I have now tracked it to its lair and shoved a stake through its heart!
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,840
    Rep Power
    5

    Default Re: Problem with integers

    That works on vampires though, not on zombLOOK OUT BEHIND YOU!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem with integers

    Quote Originally Posted by gimbal2 View Post
    That works on vampires though, not on zombLOOK OUT BEHIND YOU!
    Zombies, aren't those the nice hugable Australian little bear-like creatures, chewing on tree leaves and grabbing you for a nice hug? Ah, they're so cute with a funny nose ...

    kind regards,

    Js
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default Re: Problem with integers

    We have no bear-like creatures in Australia. Maybe you are referring to the koala. Note there is no "bear" in its name!

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problem with integers

    You are mistaken; those are snakes. Snakes are ferocious animals with huge hind legs; they hop around with great speed and live in the Antarctic.

    kind regards,

    Jos (<--- biologist ;-)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Sum of all even integers? Help?
    By psx2514 in forum New To Java
    Replies: 5
    Last Post: 04-03-2013, 06:46 PM
  2. Program help/ Integers
    By KMayers in forum New To Java
    Replies: 2
    Last Post: 11-29-2012, 01:33 PM
  3. Problem with creating a triangle out of integers...
    By ericj5555 in forum New To Java
    Replies: 1
    Last Post: 11-08-2012, 07:29 AM
  4. Printing repeating integers in an array problem!
    By andrewk1978 in forum New To Java
    Replies: 31
    Last Post: 08-07-2012, 09:47 AM
  5. Set of Integers
    By rsjava24 in forum New To Java
    Replies: 7
    Last Post: 01-28-2010, 10:29 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
  •