2 Replies - 421 Views - Last Post: 20 June 2013 - 07:33 PM Rate Topic: -----

#1 amart904  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-June 13

Conversion tables problem

Posted 20 June 2013 - 05:08 PM

hey guys, ive been working on this for hours we are supposed to write this in co

write a program that displays the following 2 tables side by side.(1 kilogram is 2.2 pounds)
ive done the code but cant figure out how to do the decimal spaces,, any help ?

Kilograms Pounds Pounds Kilograms
1 2.2 20 9.09
3 6.6 25 11.36

...
197 433.4 510 231.82
199 437.8 515 234.09

[quote name='amart904' date='20 June 2013 - 05:05 PM' timestamp='1371773101' post='1865023']
hey guys, ive been working on this for hours we are supposed to write this in co

write a program that displays the following 2 tables side by side.(1 kilogram is 2.2 pounds)
ive done the code but cant figure out how to do the decimal spaces,, any help ?

Kilograms Pounds Pounds Kilograms
1 2.2 20 9.09
3 6.6 25 11.36

...
197 433.4 510 231.82
199 437.8 515 234.09
public class WeightConversionTables
{  
  public static void main(String[] args)
  {   
    System.out.println(" | Kilo | Pounds | Pounds | Kilo");
    
    for(int kilo = 1; pounds = 20; kilo <200; kilo += 2, pounds += 5)
    {  
      int pounds = int(kilo* C * 10);
      pounds =  int(Math.round(kilo);]

im sorry i dont know how to use this page but heres my code so far 

public class WeightConversionTables
{  
  public static void main(String[] args) 
  {   
    System.out.println(" | Kilo | Pounds | Pounds | Kilo");
    
    for(int i = 1, j = 1; i <= 200 && j <= 515; i+=2, j +=5 ) 
    {   
      System.out.println(" | " + (i+1) + " | " + (i+1)*2.2 + " | "  + j + " | " + j/2.2 + " | " + j); 
    }
  }
}



*Edited: please :code:

This post has been edited by pbl: 20 June 2013 - 07:30 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Conversion tables problem

#2 schutzzz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 136
  • View blog
  • Posts: 338
  • Joined: 22-April 13

Re: Conversion tables problem

Posted 20 June 2013 - 05:50 PM

It needs to be a Double for decimal places, not an Integer
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Conversion tables problem

Posted 20 June 2013 - 07:33 PM

This does not make sense

    for(int kilo = 1; pounds = 20; kilo <200; kilo += 2, pounds += 5)    {  
      int pounds = int(kilo* C * 10);
      pounds =  int(Math.round(kilo);


you initialize pounds in your for() loop statement and do pounds +=5 in the same statement loop
but create a variable pounds inside the for() loop
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1