模拟面试-2
发布: (2026年2月9日 GMT+8 10:47)
2 分钟阅读
原文: Dev.to
Source: Dev.to
面试问题
- 请介绍一下你自己?
- 为什么从机械工程转到 IT?
- 如果机械工程是你的第一选择,为什么现在选择 IT 课程?
- 为什么选择 Java?
- Java 容易学吗?
- 编译程序涉及哪些步骤?
- 执行时会发生什么?
- 如何在不使用
System.out.println()的情况下产生输出? System.out.println()会输出什么?- 什么是控制流语句?
- 什么是
switchcase?
示例 1
switch (x) {
case 1:
System.out.print("One ");
case 2:
System.out.print("Two ");
case 3:
System.out.print("Three ");
default:
System.out.print("Default");
}
输出: Two Three Default
示例 2
switch (x) {
default:
System.out.print("Default ");
case 1:
System.out.print("One ");
case 2:
System.out.print("Two ");
}
输出: Default One Two
示例 3
switch (ch) {
case 'A':
System.out.println("A");
break;
case 65:
System.out.println("Sixty Five");
}
输出: A
('A' case 匹配;65 被视为 int。)
示例 4(switch 表达式)
String result = switch (day) {
case 1 -> "Monday";
case 2 -> "Tuesday";
case 3 -> "Wednesday";
default -> "Invalid";
};
System.out.println(result);
输出: Wednesday