Java Data Type Exercises: Inches to meters
Java Data Type: Exercise-2 with Solution
Write a Java program that reads a number in inches, converts it to meters.
The inch is a unit of length in the (British) imperial and United States customary systems of measurement now formally equal to 1/36 yard but usually understood as 1/12 of a foot.
The meter is the base unit of length in some metric systems, including the International System of Units (SI). The SI unit symbol is m.
Note: One inch is 0.0254 meter.
Test Data
Input a value for inch: 1000
Sample Solution:
Java Code:
import java.util.Scanner;
public class Exercise2 {
public static void main(String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print("Input a value for inch: ");
double inch = input.nextDouble();
double meters = inch * 0.0254;
System.out.println(inch + " inch is " + meters + " meters");
}
}
Sample Output:
Input a value for inch: 1000 1000.0 inch is 25.4 meters
Flowchart:
Java Code Editor:
Improve this sample solution and post your code through Disqus
Previous: Write a Java program to convert temperature from Fahrenheit to Celsius degree.
Next: Write a Java program that reads an integer between 0 and 1000 and adds all the digits in the integer. Input an integer between 0 and 1000.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Java: Tips of the Day
How to sort an ArrayList?
Collections.sort(testList); Collections.reverse(testList);
That will do what you want. Remember to import Collections though!
Ref: https://bit.ly/32urdSe
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework