java源文件组成部分

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
View Code

 

注意:   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

    }
}          

  注意:双引号中的内容是原样输出的

 

转载于:https://www.cnblogs.com/penphy/p/10173300.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值