首页 > 编程语言 > 详细

Java初学几个程序背诵

时间:2015-01-14 15:30:05      阅读:187      评论:0      收藏:0      [点我收藏+]

1.Hello world

class first
{
    public static void main(String[] args){
        System.out.println("Hello world");
    }
}

2.数组 -> for循环

 1 class first
 2 {
 3     public static void main(String[] args){
 4         int[] array;
 5         array = new int[5];
 6         for(int i=0;i<5;i++){
 7             array[i]=i;
 8         }
 9         for(int i=4;i>=0;i--){
10             System.out.println(array[i]);
11         }
12     }
13 }

3.简单的类:class

 

 1 class first
 2 {
 3     public static void main(String[] args){
 4         Human Person = new Human() ;
 5         Person.age();
 6         System.out.println(Person.height);
 7     }
 8 }
 9 class Human
10 {
11     void age(){
12         System.out.println("I am 12");
13     }
14     int height = 10;
15 }

 

Java初学几个程序背诵

原文:http://www.cnblogs.com/subtract/p/4223998.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!