byte short int long
float double
char
boolean

byte 타입은 -128 에서 +127 사이에 있는 숫자의 크기에서만 존재
short -32768 ~ 32767

1) short

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package 두번째;
 
public class ByteJava // 클래스 선언
{
 
    public static void main(String[] args) // main 선언
    {
        short shortVar1; // 변수선언
         
        shortVar1 = 128; // 값 대입
         
        System.out.println("shortVar1 = " +shortVar1); // 출력
    }
}





2) float / double

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package 두번째;
 
public class FloatingTest
{
    public static void main(String[] args)
    {
        float floatVar1;
        double doubleVar1;
         
        floatVar1 = 2.5f;
        // floatVar1 = 2.5; 이렇게 쓰면 2.5는 double 타입이므로 에러발생
        doubleVar1 = 2.5;
         
        System.out.println("floatVar1 =" +floatVar1);
        System.out.println("doubleVar1 =" +doubleVar1);
    }
 
}





3) char

1
2
3
4
5
6
7
8
9
10
11
12
13
package 두번째;
 
public class CharTest
{
    public static void main(String[] args)
    {
        // TODO Auto-generated method stub
        char c = 'a';
         
        System.out.println("c");
        System.out.println((int)c);
    }
}





4) boolean

1
2
3
4
5
6
7
8
9
10
11
12
13
package 두번째;
 
public class booleantest {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        boolean x = true;
         
        System.out.println(x);
 
    }
 
}





변수의 초기화
- 지역 변수, 자동 변수 : 메소드 안에 선언한 변수, 반드시 초기화를 해야한다
- 멤버 변수 : 선언한 데이터 타입의 기본 값으로 자동 초기화 된다


Posted by 코딩하는 야구쟁이
,