How Do You Write A Java Program That Converts Centimeters To Inches & Vice Versa?
Learning how to program can be a challenge, but even beginners can produce programs that solve real-world problems. A program that converts between inches and centimeters is a great starting point for writing more complex applications. Open your text editor and create a file named UnitConversion.java. In the file, create a class named UnitConversion, and add an import statement for java.util.Scanner. Your file should now look like this: import java.util.Scanner; public class UnitConversion { } Add a main function inside your class (between the curly braces). The function should look like this: public static void main(String[] args) { } Add code to your main function to create a Scanner, which will read your user’s input. This line will get the job done: Scanner s = new Scanner(System.in); Read your user’s input into a variable: double inches = s.nextDouble(); Convert the input to centimeters: double centimeters = inches * 2.54; Output the result so your user can see it: System.out.prin