middlemoon

Day02.변수 본문

Develop/JAVA

Day02.변수

중대경 2022. 7. 10. 23:15

package chap2;

 

public class VariableTest {

 

public static void main(String[] args) {

boolean b1 = true; //값 저장 선언

boolean b2 = false;

boolean b3 = 10 > 0;

 

 

System.out.println("b1의 값 출력=" + b1);// b1 저장 값 출력

System.out.println("b2의 값 출력=" + b2);

System.out.println("b3의 값 출력=" + b3);

 

int i1 = 100;

int i2 = 200;

System.out.println(i1 + i2);

System.out.println("i1+i2=" + (i1 + i2));

 

System.out.println("int최대값=" + Integer.MAX_VALUE); //int 4byte = 32bit - 2^31~ 2^31-1

System.out.println("int최값=" + Integer.MIN_VALUE); //(API 라이브러리 사용)

//Byte.MAX_VALUE 

//int i3 = 2147483647 + 1;

 

char c1 = 'a';

char c2 = '\n';

System.out.println("c2=" + c2);

System.out.println("c1=" + c1);

 

int i4 = 65;

char c4 = 'A';

System.out.println( i4 + c4); //130. String + 다른타입, 숫자+숫자

System.out.println( (char)i4); //A

System.out.println( (int)c4); //65

}

 

}

 

*코드설명

Variable은 변수라는 뜻을 갖고있다. 변수는 변할수있는 수이다. 즉, 변수가 들어가는 b1,b2,b3 라는 타입이 변수에 대한 선언이다.

데이터타입을 boolean으로 한 이유는 참과 거짓을 나타내기 위한 데이터형식이기 때문이다.

 

boolean의 타입말고도 int , char, integer.Max_value, Min_value 라는 API를 사용하여 결과값을 나오게 하였다.

 

'Develop > JAVA' 카테고리의 다른 글

JAVA 객체지향 프로그래밍 I  (0) 2023.01.12
Day05.HashMap  (0) 2022.08.15
Day04.함수  (0) 2022.07.19
Day03. 배열  (0) 2022.07.18
Day01. 자동형변환  (0) 2022.07.08
Comments