1. Member
Join Date
Nov 2013
Posts
1
Rep Power
0

## 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. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

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.

3. Member
Join Date
Feb 2012
Posts
6
Rep Power
0

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:

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. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,491
Rep Power
9

Regards,
Jim

5. Moderator
Join Date
Apr 2009
Posts
12,962
Rep Power
22

## 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.

6. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

7. Moderator
Join Date
Apr 2009
Posts
12,962
Rep Power
22

## Re: Problem with integers

Thank you.
I have now tracked it to its lair and shoved a stake through its heart!

8. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Problem with integers

That works on vampires though, not on zombLOOK OUT BEHIND YOU!

9. ## Re: Problem with integers

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

10. ## 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. ## 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 ;-)

#### Posting Permissions

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