程序的主结构:
命名规范和代码书写
代码书写
public class 类名(与新建项目名保持一致);{
public static void main(string[ ] args);(定义一个main方法,即程序的主入口){
程序操作内容
}
}
输出语句的表达
程序输出可有以下内容
输出数字
输出计算结果。
输出字符串。
输出字符串与数字的混合表达式。
输出 math类常用方法
输出当前日期时间
System.out.println(LocalDate.now()); // 当前计算机的日期
System.out.println(LocalTime.now()); // 当前计算机的时间
System.out.println(LocalDateTime.now()); // 当前计算机的日期时间
System.out.println("年份:" + LocalDate.now().getYear());
System.out.println("月份:" + LocalDate.now().getMonth());
System.out.println("月份:" + LocalDate.now().getMonthValue());
System.out.println("日期:" + LocalDate.now().getDayOfMonth());
System.out.println("星期:" + LocalDate.now().getDayOfWeek());
输出当前日期时间:
System.out.println(LocalDate.now()); // 当前计算机的日期
System.out.println(LocalTime.now()); // 当前计算机的时间
System.out.println(LocalDateTime.now()); // 当前计算机的日期时间
System.out.println("年份:" + LocalDate.now().getYear());
System.out.println("月份:" + LocalDate.now().getMonth());
System.out.println("月份:" + LocalDate.now().getMonthValue());
System.out.println("日期:" + LocalDate.now().getDayOfMonth());
System.out.println("星期:" + LocalDate.now().getDayOfWeek());
转义符
\t制表符
\n换行
\u 16进制编码的ASCII码
在转义符前面加上“\”,可输出“\n”“\t”“\u”等字符串。
代码注释
代码注释主要是写给程序员看的,因为在代码编译的class文件中并没有注释的存在。注释主要有:
单行注释//
多行注释/* */
文档注释
/*
* *
*/