• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Need help with Loops

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 74712
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic