File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need help with Loops

 
Mitch Kazlo
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I'm trying to figure out the following problem. I have the first part working correctly but it's the second part that is stumping me. It's a Kilograms to pounds console program that should have the following output. with the exception that the second set of pound and kilograms should be listed for every 5 kilograms like the second example and they have to be side by side tables.


Kilograms Pounds Pounds Kilograms
---------------------------------------------------------
1 2.2 2.2 1
3 6.6 6.6 3
5 11 11 5
7 15.4 15.4 7


Should be:

Kilograms Pounds Pounds Kilograms
---------------------------------------------------------
1 2.2 xxxx 5
3 6.6 xxxx 10
5 11 xxxx 15
7 15.4 xxxx 20


Here is the code I have:



Any help you can give me is greatly appreciated.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1802
12
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try commenting out line 17, that'll get rid of the pounds outputting twice. See what it looks like and add more tabs if necessary.

I'm not sure what you mean by side by side tables... like on the right it needs to multiply both values by 5? If you use the code tag for the output it will keep the spacing and maybe be more descriptive... [EDIT] ohohoh I see.....


Maybe doing a second calculation inside the if statement:



Is that it?
 
Mitch Kazlo
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 2 table side by side should look like this:

KG LBS LBS KG
_________________
1 2.2 11.0 5
3 6.6 22.0 10
5 11.0 33.0 15
7 15.4 44.0 20

The second table to the right increments by 5, the first one on the left checks to see if i is divisible by 2 therefore only printing the odd numbers for KG's. I need to figure out how to create the second set of numbers right next to the first set which I think should be checking to see if i % 5 == 0 but every time I try to do that I get bad results. I've tried another if statement.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1802
12
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I was trying to say before. If you look for a % 5 = 0, it misses all the ones that end in 5.

[EDIT] fixed typos
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Why are you using DecimalFormat; that went out of fashion 5 years ago when Formatter and the printf and format methods in System.out were introduced?
 
Mitch Kazlo
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch Janeice. I made a couple of modifications and this code is working to solve the problem.



Campbell, Thanks for the advice. I'll try those.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1802
12
Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic