Created
June 15, 2013 03:08
-
-
Save LernerProductions/5786703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class UnitConverter{ | |
public static void main (String args[]){ | |
Scanner Keyboard=new Scanner(System.in); | |
System.out.print("Select a number"); | |
int num=Keyboard.nextInt(); | |
System.out.println("Select the units. 1=miles, 2=yards, 3=feet, 4=inches"); | |
int unit=Keyboard.nextInt(); | |
double inches; | |
double feet; | |
double yards; | |
double miles; | |
switch (unit){ | |
case 1: | |
miles=num; | |
yards=1760*num; | |
feet=5280*num; | |
inches=63360; | |
System.out.println("Miles: "+miles); | |
System.out.println("Yards: "+yards); | |
System.out.println("Feet: "+feet); | |
System.out.println("Inches: "+inches); | |
break; | |
case 2: | |
miles=num/1760; | |
yards=num; | |
feet=3*num; | |
inches=36*num; | |
System.out.println("Miles: "+miles); | |
System.out.println("Yards: "+yards); | |
System.out.println("Feet: "+feet); | |
System.out.println("Inches: "+inches); | |
break; | |
case 3: | |
miles=num/5280; | |
yards=num/3; | |
feet=num; | |
inches=12*num; | |
System.out.println("Miles: "+miles); | |
System.out.println("Yards: "+yards); | |
System.out.println("Feet: "+feet); | |
System.out.println("Inches: "+inches); | |
break; | |
case 4: | |
miles=num/63360; | |
yards=num/36; | |
feet=num/12; | |
inches=num; | |
System.out.println("Miles: "+miles); | |
System.out.println("Yards: "+yards); | |
System.out.println("Feet: "+feet); | |
System.out.println("Inches: "+inches); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment