0

わかりました、私はプログラミングの完全な初心者で、Java でコーディングを始めたばかりです。温度変換 (摂氏から華氏) のコードを書き込もうとしましたが、何らかの理由で実行できません! このコードのエラーを見つけるのを手伝ってください(どんなにばかげているかもしれません)。

コードは次のとおりです。

  package tempConvert;

  import java.util.Scanner;

  public class StartCode {

      Scanner in = new Scanner(System. in );

      public double tempInFarenheit;

      public double tempInCelcius;

      {
          System.out.println("enter the temp in celcius");

          tempInCelcius = in .nextDouble();

          tempInFarenheit = (9 / 5) * (tempInCelcius + 32);

          System.out.println(tempInFarenheit);
      }
  }
4

4 に答える 4

4

プログラムを実行するための開始点である main メソッドを書き忘れました。コードを修正させてください。

import java.util.Scanner;

public class StartCode 
{
    Scanner in = new Scanner (System.in); 
    public double tempInFarenheit;
    public double  tempInCelcius;

public static void main (String[] args)

    {
        System.out.println("enter the temp in celcius");

        tempInCelcius = in.nextDouble() ;    
        tempInFarenheit = (9/5)*(tempInCelcius+32);

        System.out.println(tempInFarenheit);
    } 
}
于 2012-04-18T20:09:37.623 に答える
1

これはあなたにとってよりうまくいくと思います:

import java.util.Scanner;

public class StartCode
{
    public static void main(String[] args) {
        Scanner in = new Scanner (System.in);
        double tempInFarenheit;
        double  tempInCelcius;
        System.out.println("enter the temp in celcius");
        tempInCelcius = in.nextDouble() ;
        tempInFarenheit = 1.8*tempInCelcius+32;
        System.out.println(tempInFarenheit);
    }
}

華氏の方程式が間違っていました。整数除算もあなたのためではありません。

于 2012-04-18T20:36:24.893 に答える
0
import java.util.*;
public class DegreeToFahrenheit {


    public static void main(String[] args) 
    {
        Scanner input = new Scanner(System.in);  

        System.out.println("Enter a temperature: ");  
        double temperature = input.nextDouble();  
        System.out.println("Enter the letter of the temperature type. Ex: C or c for celsius, F or f for fahrenheit.: ");  

        String tempType = input.next();  


        String C = tempType;  
        String c = tempType;  

        String F = tempType;  
        String f = tempType;  

        double celsius = temperature;  
        double fahrenheit = temperature;  

        if(tempType.equals(C) || tempType.equals(c)) { 
            celsius = (5*(fahrenheit-32)/9);  
            System.out.print("The fahrenheit degree " + fahrenheit + " is " + celsius + " in celsius." );


        }  


        else if(tempType.equals(F) || tempType.equals(f)) {  

            fahrenheit = (9*(celsius/5)+32);  
            System.out.print("The celsius degree " + celsius + " is " + fahrenheit + " in fahrenheit." ); 
        }  

        else {  
            System.out.print("The temperature type is not recognized." );  
        }  
    }  

}  
于 2013-01-10T18:37:25.523 に答える
0

main メソッドが必要です。また、スケルトン コード (メイン メソッドの構文を含む) を生成できる Eclipse などの IDE を使用することをお勧めします。

于 2012-04-18T20:12:55.530 に答える