Wrapper 클래스

2008/05/13 12:24

class WrapExam 
{
 public static void main(String[] args)
 {
  Integer wrapi = new Integer(100);
  Double wrapd = new Double(55.7);
  int i = 100;
  double d = 55.5;
  double dl;
  dl = d+i;
  System.out.println(i+d);
  System.out.println(Integer.toString(i) + Double.toString(d));
  System.out.println(wrapi.toString() + wrapd.toString());
  System.out.println(wrapi + wrapd);
 }
}



class ValueofExam
{
 public static void main(String[] args)
 {
  String stri = "123456";
  String strd = "123.56";
 
  //String strs="adfd";
  //NumberFormatException 예외 발생
  System.out.println(Integer.valueOf(stri));
  System.out.println(Double.valueOf(strd));
  System.out.println(stri+strd);
  System.out.println(Integer.valueOf(stri)+Double.valueOf(strd));
  System.out.println(Integer.parseInt(stri) + Double.parseDouble(strd));

 }
}



import java.io.*;
class parseDataExam
{
 public static void main(String[] args)
 {
  String a="", b="";
  int sum=0;
  float average = 0;
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  try
  {
   System.out.print("정수입력 >");
   a = in.readLine();
   System.out.print("정수입력 >");
   b = in.readLine();

  }
  catch(IOException e)
  {
   System.out.println(e);
  }

  System.out.println("input data : " + a + " " + b);
  int c = Integer.parseInt(a);
  int d = Integer.parseInt(b);
  sum = c+d;
  average = sum/2;
  System.out.println(a + " + " + b + " = " + sum);
  System.out.println("평균 = " + average);

  System.out.println("Hello World!");
 }
}

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 쿠겔

01. CLASS

2008/03/25 12:16

사용자 삽입 이미지

name 이 private로 되어있기 때문에, main 클래스(sunrin0325)에서 쓸 수 없고,
Stuent 안에서만 쓸 수 있다.

private     클래스 o, 하위클래스 x, 동일 패키지 x, 모든 클래스 x
default     클래스 o, 하위클래스 x, 동일 패키지 o, 모든 클래스 x
protected 클래스 o, 하위클래스 o, 동일 패키지 o, 모든 클래스 x
public      클래스 o, 하위클래스 o, 동일 패키지 o, 모든 클래스 o





클래스 변수 Static

서로 다른곳에서 호출하는 것 이지만 공유 가능
클래스 변수는 하나의 클래스로부터 생성된 객체들 사이의 공통된 속성을 표현하는데 사용될 수 있다.
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 쿠겔