1

我正在为飓风规模创建一个程序,它给我带来了问题。所有错误都发生在 else if 行上。帮助将不胜感激。这是代码:

import java.util.Scanner;

public class hurricaneScale {
    public static void main(String[]args) {
    Scanner in = new Scanner(System.in);
    System.out.print("Please enter the wind speed (in mph):");
    double windSpeed = in.nextln();

    if (windSpeed < 39) {
      System.out.print("      Category          Wind Speed   Storm Surge   Damage Potential");
      System.out.println("Tropical Depression   < 39 mph         -            Minimal    ");
    } 
    else if (windSpeed >= 39 && <=73) {
      System.out.print("    Category           Wind Speed   Storm Surge   Damage Potential");
      System.out.println("Tropical Storm      39 - 73 mph        -            Minimal    ");
    } 
    else if (windSpeed >= 74 && <=95) {
      System.out.print("   Category             Wind Speed   Storm Surge   Damage Potential");
      System.out.println("Hurricane 1          74 - 95 mph   4.0' - 5.0'   Minimal to extensive");
    } 
    else if (windSpeed >= 96 && <=110) {
      System.out.print("   Category           Wind Speed   Storm Surge   Damage Potential");
      System.out.println("Hurricane 2        96 - 110 mph   6.0' - 8.0'      Moderate    ");
    } 
    else if (windSpeed >= 111 && <=130) {
      System.out.print("   Category          Wind Speed      Storm Surge    Damage Potential");
      System.out.println("Hurricane 3      111 - 130 mph     9.0' - 12.0'       Extensive    ");
    } 
    else if (windSpeed >= 131 && <=155) {
      System.out.print("   Category          Wind Speed      Storm Surge        Damage Potential");
      System.out.println("Hurricane 4      131 - 155 mph    13.0' - 16.0'            Extreme    ");
    } 
    else if (windSpeed > 155) {
      System.out.print("   Category        Wind Speed      Storm Surge      Damage Potential");
      System.out.println("Hurricane 5      > 155 mph         > 18.0'           Catastrophic ");
    }
  }
}
4

3 回答 3

1

以下语法无效:

else if (windSpeed >= 39 && <=73)

您需要将其替换为:

else if (windSpeed >= 39 && windSpeed <=73)

您必须为每次出现都执行此操作。

于 2013-10-28T03:44:21.070 回答
0

您需要为windSpeed所有 if 条件添加变量。像这样

windSpeed >= 39 && windSpeed <=73

你不能写windspeed >= 39 && <=73,这是不正确的。

于 2013-10-28T03:44:23.217 回答
0
windSpeed >= 39 && windSpeed <=73
于 2013-10-28T03:45:07.213 回答