2016-10-06 9 views
0

私のメソッドを呼び出すのに助けが必要です。それは"the method fahrtoCel" is undefined for the "TempConversion"と言います。CelciusからFahrまでのメソッドを使用していますが、メソッドは定義されていません

import java.util.Scanner; 

public class TempConversion { 

    public static void main(String[] args) { 

     System.out.println("===CONVERTING TEMPERATURE====="); 
     ConvertTemp(); 
    } 

     private static void ConvertTemp(){ 
      Scanner s = new Scanner(System.in); 
      System.out.println("Press 1: Convert Celcius to Fahrenheit\nPress 2: Convert Fahrenheit to Celcius\n"); 
      int select = s.nextInt(); 

      if (select==1){ 
       System.out.print("Enter the fahrenheit: "); 
       celtoFahr(); 
      } else if (select==2){ 
       System.out.print("Enter the celcius: "); 
       fahrtoCel(); 
      } else{ 
       System.out.println("exit"); 

      } 

      private static void celtoFahr(){ 
       double temperature = s.nextDouble(); 
       double celcius = 5.0/9.0*(temperature-32); 

      } 
      private static void fahrtoCel(){ 
       double temperature = s.nextDouble(); 
       double fahrenheit = 9.0/5.0*(temperature+32); 
      } 

    } 

} 

答えて

0

あなたはしかし、行う場合は、決算に}

private static void ConvertTemp(){ 
    Scanner s = new Scanner(System.in); 
    System.out.println("Press 1: Convert Celcius to Fahrenheit\nPress 2: Convert Fahrenheit to Celcius\n"); 
    int select = s.nextInt(); 

    if (select==1){ 
     System.out.print("Enter the fahrenheit: "); 
     celtoFahr(); 
    } else if (select==2){ 
     System.out.print("Enter the celcius: "); 
     fahrtoCel(); 
    } else{ 
     System.out.println("exit"); 

    } 

    // add closing curly 
    } 
    private static void celtoFahr(){ 
    ... 

が欠落している、sはそうスキャナを受け入れるためにあなたの方法を変更する適用範囲外となります。

private static void ConvertTemp(){ 
    Scanner s = new Scanner(System.in); 
    .... 
     celtoFahr(s); 
    .... 
} 

private static void celtoFahr(Scanner s){ 
    .... 
} 

あなたは、EclipseのようなIDEを使用している場合、このエラーはすぐに明らかであろう

関連する問題