Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting

 
Michael Mikhail
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. I`m new to java, well actually to programing and i`m tryin to solve a problem but i can`t seem to be able to solve it. I have to display 12 meters inch by inch and output a blank line every 12 inches. Can someone help me with that?
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to have to give more details on what exactly you're trying to do.
 
Michael Mikhail
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Display 12 feet
of conversions, inch by inch. Output a blank line every 12 inches. (One meter equals
approximately 39.37 inches.)

this is what i`m asked to do. I`m trying but i can`t seem to able to solve this
 
Koen Aerts
Ranch Hand
Posts: 344
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I still don't know what it is you're having a problem with. Do you need to know how to print characters on the console, or how to create a graphical interface where you draw lines and dots, or more generally how to mathematically approach this problem by Java code?
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Display 12 feet of conversions, inch by inch

As we know 1 feet = 12 inches
so 12 feet = 12/1* 12
Now my question is are you taking input from user or its hard coded.

2. Output a blank line every 12 inches
check inches every 12 and output " "

I hope this pseudo code will help otherwise where exactly you are having a problem. Is it logic or code? If its code please post code so we can direct you in right direction. Thanks
 
Michael Mikhail
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. I got the following example

class GalToLitTable {
public static void main(String args[]) {
double gallons, liters;
int counter;
counter = 0;
for(gallons = 1; gallons <= 100; gallons++) {
liters = gallons * 3.7854; // convert to liters
System.out.println(gallons + " gallons is " +
liters + " liters.");
counter++;
// every 10th line, print a blank line
if(counter == 10) {
System.out.println();
counter = 0; // reset the line counter
}
}
}
}

and the exercise says "Adapt Project so that it prints a conversion table of inches to meters. Display 12 feet
of conversions, inch by inch. Output a blank line every 12 inches. (One meter equals
approximately 39.37 inches.)".

Think i misunderstood what it asked me to do.
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike the logic remains the same. Everything is already given. I just converted that example for inches to meters.

1 inches = 0.0254 meters



Use above line in the loops and output

Logic: print after 12 so



Hope this helps. If you understand the mathematical logic then it should be fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic