Files
gc-plan/week1/day01/HelloWorld.java
2026-04-29 23:45:17 +08:00

37 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package day01;
/**
* 第 1 天Hello World
* 目标:理解 Java 程序的基本结构和运行方式
*
* 概念速查:
* public class —— 声明一个公共类,类名必须和文件名一致
* public static void main(String[] args) —— 程序的入口方法
* System.out.println() —— 向控制台输出一行文字
*
* 运行方式:
* javac HelloWorld.java (编译生成 HelloWorld.class
* java HelloWorld (运行)
*/
public class HelloWorld {
public static void main(String[] args) {
// 1. 最简单的输出
System.out.println("Hello, Java!");
// 2. 加点花样:用转义字符
System.out.println("-------------------");
System.out.println("欢迎来到 Java 世界!");
System.out.println("-------------------");
// 3. print vs printlnprint 不换行)
System.out.print("Java ");
System.out.print("一次编译,");
System.out.println("到处运行。");
// 4. 转义字符
System.out.println("第一行\n第二行"); // \n 换行
System.out.println("姓名\t年龄\t成绩"); // \t 制表符
System.out.println("他说:\"你好\""); // \" 双引号
}
}