首页 > 代码库 > Java初学几个程序背诵

Java初学几个程序背诵

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 Human10 {11     void age(){12         System.out.println("I am 12");13     }14     int height = 10;15 }

 

Java初学几个程序背诵