The problem In this exercises write a program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter. Here is a sample run:
Enter a value for feet: 16.5
16.5 feet is 5.0325 meters
Breaking it down public static void main ( String [] Strings ) {
Scanner input = new Scanner ( System . in );
System . out . print ( "Enter a value for feet: " );
double feet = input . nextDouble ();
input . close ();
double meters = convertFeetToMeters ( feet );
System . out . println ( feet + " feet is " + meters + " meters" );
}
private static double convertFeetToMeters ( double feet ) {
double meters = feet * 0.305 ;
return meters ;
}
Output Enter a value for feet: 200
200.0 feet is 61.0 meters
Convert feet into meters posted by Justin Musgrove on 27 March 2016
Tagged: java, java-exercises-beginner, intro-to-java-10th-edition, and ch2
Share on: Facebook Google+