# Problem with integers

• 11-15-2013, 03:37 PM
RichardYang
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.
• 11-15-2013, 03:43 PM
gimbal2
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.
• 11-15-2013, 04:29 PM
kmlam585
Quote:

Originally Posted by RichardYang
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:

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);     } }```
• 11-15-2013, 04:35 PM
jim829

Regards,
Jim
• 11-15-2013, 05:30 PM
Tolls
Re: Problem with integers
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.
• 11-15-2013, 05:39 PM
gimbal2
Re: Problem with integers
• 11-15-2013, 05:42 PM
Tolls
Re: Problem with integers
Thank you.
I have now tracked it to its lair and shoved a stake through its heart!
• 11-15-2013, 05:44 PM
gimbal2
Re: Problem with integers
That works on vampires though, not on zombLOOK OUT BEHIND YOU!
• 11-15-2013, 06:46 PM
JosAH
Re: Problem with integers
Quote:

Originally Posted by gimbal2
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
• 11-16-2013, 01:57 AM
Junky
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-16-2013, 10:47 AM
JosAH
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 ;-)