java else without if_Java Error: 'else' without 'if'

获取没有if语句的else:

import java.util.Scanner;

public class LazyDaysCamp

{

public static void main (String[] args)

{

int temp;

Scanner scan = new Scanner(System.in);

System.out.println ("What's the current temperature?");

temp = scan.nextInt();

if (temp > 95 || temp < 20);

System.out.println ("Visit our shops");

else if (temp <= 95)

if (temp >= 80)

System.out.println ("Swimming");

else if (temp >=60)

if (temp <= 80)

System.out.println ("Tennis");

else if (temp >= 40)

if (temp < 60)

System.out.println ("Golf");

else if (temp < 40)

if (temp >= 20)

System.out.println ("Skiing");

}

}

我需要使用级联,如果这就是为什么它看起来像那样。此外,能否请你知道我是否正确进行了级联?如果一直无法找到一个很好的级联示例,那么我只是尽力了解级联的含义。

LazyDaysCamp.java:14: error: 'else' without 'if'

else if (temp <= 95)

^

1 error

那是我得到的错误

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值