lundi 23 avril 2018

Metric Conversion

I' trying to allow the user to do conversions in the metric system. So far I'm starting off with converting Inches to Centimeters and I wrote the method down but nothing is being displayed. I tried to print out num using an if statement but it just left it as its original value. Please help.

 import java.util.Scanner;
   public class MetricConversion {
     public static void main(String[] args) {
       Scanner scan =new Scanner(System.in);
       int choice; int num;
        System.out.println(" Enter a number: ");
       num = scan.nextInt();

      System.out.println("Convert:");
      System.out.println();
      System.out.println(" 1. Inches to centimeters     
      System.out.println(" 2. Feet to Centimeters           
      System.out.println(" 3. Yards to Meters               
      System.out.println(" 4. Miles to Kilometers       
      System.out.println();

      System.out.println("Enter Your choice: ");
      choice = scan.nextInt();

     if (choice == 1) {
        InchesToCentimeters(num);
     System.out.println(num);
     }
 }

 public static double InchesToCentimeters(int num){
     double centimeters;
     centimeters = num * 2.54;
     return centimeters;





 }

Aucun commentaire:

Enregistrer un commentaire