1、用if语句完成: 如果今天是星期天就出去玩,如果今天是星期六就在家里玩,否则就 “好好学习,天天向上”。 2、用switch语句完成: 某学校一名初中生的补课安排:星期一补习数学,星期二补习语文,星期三补习英语,星期五补习化学,其余时间休息。
时间: 2024-09-22 21:02:02 浏览: 50
1. 使用Python语言来表示这个逻辑:
```python
import datetime
# 获取当前日期
today = datetime.datetime.now().strftime("%A")
if today == "星期天" or today == "星期六":
action = "出去玩" if today == "星期天" else "在家里玩"
else:
action = "好好学习,天天向上"
print(f"今天是{today},{action}")
```
如果你需要使用Java语法,可以这样做:
```java
import java.time.DayOfWeek;
public class Main {
public static void main(String[] args) {
DayOfWeek dayOfWeek = DayOfWeek.of(LocalDate.now());
String action;
switch (dayOfWeek) {
case SUNDAY:
case SATURDAY:
action = dayOfWeek == DayOfWeek.SATURDAY ? "在家里玩" : "出去玩";
break;
default:
action = "好好学习,天天向上";
}
System.out.println("今天是" + dayOfWeek + ", " + action);
}
}
```
2. 使用Java switch语句表示学生的补课安排:
```java
DayOfWeek currentDay = DayOfWeek.of(LocalDate.now());
switch (currentDay) {
case MONDAY:
action = "补习数学";
break;
case TUESDAY:
action = "补习语文";
break;
case WEDNESDAY:
// 如果周三没有特殊安排,一般默认休息
action = "休息";
break;
case THURSDAY:
action = "补习英语";
break;
case FRIDAY:
action = "补习化学";
break;
default:
action = "休息";
}
System.out.println("今天是" + currentDay + ", " + action);
```
阅读全文