16.3k views
3 votes
Write a program that reads a number in meters convert it to feet and displays the result in java.

User Dree
by
6.1k points

1 Answer

6 votes

Answer:

//import the Scanner class

import java.util.Scanner;

//Begin class definition

public class Converter {

//Begin main method

public static void main(String args[]) {

//Create an object of the Scanner class

//To allow for reading from standard inputs

Scanner input = new Scanner(System.in);

//Prompt the user to enter some number in meters

System.out.println("Enter the number in meters: ");

//Store the user's input in a variable of type double

double meters = input.nextDouble();

//Convert the user's input to feet

//Since 1 meter = 3.28 feet

double feet = meters * 3.28;

//Display the result

System.out.println("The number in feet is " + feet);

} //End of main method

} // End of class definition

Sample Output

>> Enter the number in meters:

2

The number in feet is 6.56

Step-by-step explanation:

The program above has been written in Java and it contains comments explaining each line of the code. Kindly go through the comments.

A sample output resulting from a run of the code has also been provided.

The snapshots of the program and the sample output have been attached to this response.

Write a program that reads a number in meters convert it to feet and displays the-example-1
Write a program that reads a number in meters convert it to feet and displays the-example-2
User Quirky Purple
by
6.3k points