令牌“< =”上的语法错误,删除此令牌

时间:2013-10-28 03:42:24

标签: java syntax token

我正在创建一个飓风规模的程序,它给了我一些问题。所有错误都发生在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 ");
    }
  }
}

3 个答案:

答案 0 :(得分:1)

以下语法无效:

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

您需要将其替换为:

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

每次出现都必须这样做。

答案 1 :(得分:0)

您需要将windSpeed变量添加到所有if条件中。喜欢这个

windSpeed >= 39 && windSpeed <=73

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

答案 2 :(得分:0)

windSpeed >= 39 && windSpeed <=73