programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# converting

Michael Mikhail
Greenhorn
Posts: 5
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
You're going to have to give more details on what exactly you're trying to do.

Michael Mikhail
Greenhorn
Posts: 5
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
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
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
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
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.

 Consider Paul's rocket mass heater.