Write a program that reads a distance in yard, feet, inches and converts to metres.
[ For JAVA programming ]
• Need Quality answer !!
Answers
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
Java datatype Exercises: Inches to meters
I hope it helpful !
Here is your answer :—
import java.util.Scanner;
class Question3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("To convert yards into meter enter 1");
System.out.println("to convert inches into meter enter 2");
System.out.println("to convert feet into metre enter 3");
System.out.println("to exit the program press 0");
int choice = sc.nextInt();
double dis = 0;
switch(choice) {
case 0:
System.out.exit(0);
break;
case 1:
System.out.println("enter the distance in yards");
dis = sc.nextDouble();
System.out.println("distance in metre is "+ (dis*0.914));
break;
case 2:
System.out.println("enter the distance in inches");
dis = sc.nextDouble();
System.out.println("distance in metre is "+ (dis*0.0254));
break;
case 3:
System.out.println("enter the distance in yards");
double dis = sc.nextDouble();
System.out.println("distance in metre is "+ (dis*0.305));
break;
default:
System.out.println("Wrong choice");
break;
}
}
}
Hope you understand :)