15일차 강의 정리
래퍼클래스
1. Integer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | public class Ex01 { public static void main(String[] args) { //Wrapper class //integer Integer i = 123; //오토박싱(자동으로 객체를 씌우는것)<->언박싱 int a=(int)2147483647; //원시자료형 Integer one = new Integer(3); Integer one2 = new Integer(a); //정수실수형 문자열 Integer one3 = new Integer("3"); Integer one4 = one2+one3; int one5= one2.intValue()+one3.intValue(); one4 = new Integer(one5); int one6 = Integer.valueOf("234"); //return 타입이 int System.out.println(one4.doubleValue()); //.intValue() 이것은 자동으로 System.out.println(Integer.MAX_VALUE); System.out.println(Integer.MIN_VALUE); System.out.println(Integer.SIZE); System.out.println(one.intValue()==one3.intValue()); System.out.println("------------------------"); System.out.println(one6); System.out.println(one3.compareTo(one)); //같으면 0 ,3가 크면 1,작으면 -1 System.out.println(Integer.reverse(9)); //? System.out.println(Integer.toBinaryString(4)); //2진수로 반환(문자열로 반환된다) System.out.println(Integer.toOctalString(8)); //8진수로 반환 System.out.println(Integer.toHexString(19)); //16진수 } } class Integ{ int a; public Integ(int a){ this.a=a; } public Integ(String st){ this.a=Integer.parseInt(st); } } | cs |
2. char
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | public class Ex02 { public static void main(String[] args) { //char // Character ch = new Character('a'); // System.out.println(Character.isDigit('+')); //숫자 인지 확인 // System.out.println(Character.isLetter('a')); //문자 인지 확인 // System.out.println(Character.isUpperCase('A')); //문자이면서 대문자인지 // System.out.println(Character.isLowerCase('a')); //소문자인지 // System.out.println(Character.isSpace('a')); //공백인지 // System.out.println(Character.isDefined(' ')); //유니코드인지 char[] ch = {'함','a','A','!',' ','5'}; for(int i=0;i<ch.length;i++){ System.out.print(ch[i]+"는 "); if(Character.isDefined(ch[i])){ System.out.println("유니코드인 "); } if(Character.isUpperCase(ch[i])){ System.out.print("대"); } if(Character.isLowerCase(ch[i])){ System.out.print("소"); } if(Character.isLetter(ch[i])){ System.out.println("문자입니다"); } if(Character.isDigit(ch[i])){ System.out.println("숫자입니다."); } if(Character.isWhitespace(ch[i])){ System.out.println("공백문자입니다."); } } } } | cs |
3. boolean
1 2 3 4 5 6 7 8 9 10 11 12 13 | public class Ex03 { public static void main(String[] args) { // boolean Boolean boo = new Boolean(Boolean.TRUE); Boolean boo2 = new Boolean("false"); if(boo2.booleanValue()){ System.out.println("참입니다"); }else{ System.out.println("거짓입니다."); } } } | cs |
4. byte
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | public class Ex04 { public static void main(String[] args) { //byte Byte by1 = new Byte("1"); Byte by2 = new Byte("2"); byte a = (byte)1; byte b = (byte)2; byte c = (byte)((int)a+(int)b); // Byte by3 =(Byte)((byte)(by1.byteValue()+by2.byteValue())); // System.out.println(by3+3); Byte by3 =new Byte((byte)(by1.byteValue()+by2.byteValue())); System.out.println(by3+3); System.out.println((byte)(Byte.MAX_VALUE+1)); Short sh1 = Short.MAX_VALUE; Short sh2 = Short.MIN_VALUE; System.out.println(sh1); System.out.println(sh2); Long lo1 = new Long(9223372036854775806l); System.out.println(lo1); System.out.println(lo1.intValue()); System.out.println(Long.toBinaryString(lo1)); System.out.println(Long.toOctalString(lo1)); System.out.println(Long.toHexString(lo1)); Long lo2 = Long.MAX_VALUE; Long lo3 = Long.MIN_VALUE; System.out.println(lo2); System.out.println(lo3); } } | cs |
5. float
1 2 3 4 5 6 7 8 9 10 11 12 13 | public class Ex05 { public static void main(String[] args) { //Float Float f1 = new Float(10.0/3); System.out.println(f1); System.out.println(f1.byteValue()); System.out.println(f1.intValue()); System.out.println(f1.floatValue()); System.out.println(f1.doubleValue()); System.out.println(f1.isInfinite()); } } | cs |
'* Programming > JAVA' 카테고리의 다른 글
DAY16 접근제한자 (0) | 2016.07.26 |
---|---|
회원가입 프로그램 (0) | 2016.07.25 |
DAY15 String " "기준으로 불러오기 (0) | 2016.07.25 |
DAY14 Lotto(객체지향) (0) | 2016.07.25 |
DAY14 StringBuffer (0) | 2016.07.21 |