zoukankan      html  css  js  c++  java
  • -4


    1.枚举:

    • 枚举里常量的数据类型是int类型,
    • 枚举无构造器
    • 枚举类其实是继承了Enum类
    • 枚举中的常量字符串通过调用valueOf方法来转换成枚举类型的,并且因为枚举类没有构造器
      所以直接用类名调用valueOf方法,还有,valueOf转换的常量字符串必须是枚举中已存在的常量数据
    enum sex{
    	MALE,FAMALE;
    }
    //调用
    sex s = sex.valueOf("MALE");//且字符串的数据必须是枚举中存在的常量数据
    System.out.println(s);
    
    • 遍历枚举中的元素
    		sex[] s2 = sex.values();
    		for (sex sex2 : s2) {
    			System.out.println(sex2);
    		}
    	}
    

    2.数组:
    静态初始化:int[] a = new int[]{};
    动态初始化:int[] b = new int[5];
    3.对象数组:

    class person{
        String name;
        int age;
        person(String n,int a){
            name = n;
            age = a;
        }
        	public String toString() {
    		return "person [name=" + name + ", age=" + age + "]";
    	}
    }
    class test{
        public static void main(String[] args){
            person p[] = new person [2];
            person p1 = new person("zs",18);
            person p2 = new person("ls",87);
            p[0] = p1;
            p[1] = p2;
            for(int i=0;i<2;i++){
                System.out.println(p[i]);
            }
        }
    }
    
  • 相关阅读:
    低落
    栗子
    Wireless Password HDU
    考研路茫茫——单词情结 HDU
    DNA Sequence POJ
    HDU 6138 Fleet of the Eternal Throne 多校#8 AC自动机
    Rikka with Candies HDU
    Wavel Sequence HDU
    Counting Divisors HDU
    Codeforces Round #424 E. Cards Sorting 线段树/数据结构瞎搞/模拟
  • 原文地址:https://www.cnblogs.com/-zero/p/12256477.html
Copyright © 2011-2022 走看看