1 class HelloWorld{ 2 public static void main(String[ ] args) { 3 System.out.print("HelloWorld!!!") ; 4 } 5 } 6 7
一.编写类也叫外部结构
1 class HelloWorld{ 2 3 } #PS: class是声明类
二.编写main方法,也叫做主方法或程序的入口
1 class helloworld { 2 3 public static void main (String[ ] args) { 4 5 } 7 }
##public static void main (String[] args){
...;
} 为程序的入口
注意: 1.编写在类中
2.在一个类中的main方法是可有可无的
3.如果编写main方法,则在一个类中最多有一个
三.编写代码
一.输出语句
System.out.print (编写大小写字母,汉字,数字,以及特殊符号,但是输出后不换行)
System.out.println (输出内容同上,但是输出后换行)

1 class HelloWorld{ 2 public static void main(String[ ] args) { 3 System.out.println("HelloWorld!!!") ; 4 System.out.print("hello") ; 5 System.out.println("HelloWorld") ; 6 System.out.print("1233123123123123") ; 7 8 } 9 } 10 输出结果为: HelloWorld!!! helloHelloWorld 1233123123123123
注意: 1.将代码编写在入口中
2.可以在入口中编写n条语句,语句就是以" ; "英文分号作为结尾
PS:
class HelloWorld{
public static void main(String[ ] args) {
System.out.println(1 + 2 + 3) ; 输出结果为6
System.out.println("1 + 2 + 3"); 输出结果为 1 + 2 + 3
}
}
注意:双引号中的内容是原样输出的