In: Computer Science
Meant to be written in Java JDK 14.0
Write a program to display the conversion table from meter to feet using formatted output (printf()): 1 meter = 3.28084 feet; 1 foot = 12 inch When display the number, round the number to 2 decimal places. Set the number in the 1st the 2nd columns to the left align, set the 3rd column to the right align: meter(s) feet inch(es) 1 3.28 37.37 2 x.xx xx.xx 3 x.xx xxx.xx
Complete code in java:-
import java.util.*;
// Main class
class Conversion {
// Main method
public static void main(String ... args) {
// Creating three arrays, one array
for each column.
double []meters = new
double[6];
double []feets = new
double[6];
double []inches = new
double[6];
// Doing conversion
// Between units
for(int i = 0; i < 6; i++)
{
meters[i] =
i+1;
feets[i] =
meters[i]*3.28084;
inches[i] =
feets[i]*12;
}
// Printing columnwise formatted
output.
System.out.printf("%-22s|%-22s|%-26s\n", "Meters", "Feets",
"Inches");
for(int i = 0; i < 6; i++)
{
System.out.printf("%-22.2f|%-22.2f|%-26.2f\n", meters[i], feets[i],
inches[i]);
}
}
}
Screenshot of output:-