본문 바로가기
반응형

학습/JAVA24

3. 연산자(1) - 연산자 종류 public class OperationPriority { public static void main(String[] args) { System.out.println("12를 5로 나누었을 때 나머지 : " + 12 % 3); // 산술연산자 연산방향 : 왼쪽에서 오른쪽 int num = 9 * 4 / 3 % 5; System.out.println("num=" + num); // 대입연산자의 연산 방향 : 오른쪽에서 왼쪽 int a, b, c; a=b=c=5; System.out.println("a=" + a); System.out.println("b=" + b); System.out.println("c=" + c); } } 값 12를 5로 나누었을 때 나머지 : 0 num=2 a=5 b.. 2022. 9. 28.
3. 타입 변환 - 타입 변환 - 자동 타입 변환 public class PromotionExample { public static void main(String[] args) { byte byteValue = 10; // 2byte 정수 int intValue = byteValue; // 자동타입변환 byte -> int System.out.println(intValue); char charValue = '가'; // 2byte intValue = charValue; // 재할당 44032 System.out.println(intValue); intValue = 500; // 4byte long longValue = intValue; // 8byte int -> long System.out.println(longVal.. 2022. 9. 27.
2. 데이터 타입 - 기본 타입 - 데이터의 크기 단위 - 기본타입 선언 및 초기화 public class PrimitiveType { public static void main(String[] args) { // 정수 타입 byte byteValue = 100; char chValue = 'F'; short shValue = 101; int intValue = 124; long longvalue = 1535; // 실수 타입 float floatValue1 = 10.111f; float floatValue2 = 3.14F; // 접미사 (f, F)생략 불가능 double doubleValue1 = 3.141592D; double doubleValue2 = 3.141592d; double doubleValue3 = 3.1.. 2022. 9. 27.
1. 변수 - 변수 종류 int : 정수 타입 double: 실수 타입 float: 실수 타입 char: 문자 타입 String: 문자열 타입 등.. - 변수 선언시 첫 글자는 관례적으로 소문자로 한다. 소문자로 시작 (대 소문자 구분) $, _ 가능 (숫자로 시작 안됨) 띄어써야할 경우 대문자로 구분 - 카멜 표기법 (ex. maxSpeed, firstName) 변수명의 길이 제한 없음 예약어는 변수명으로 사용할 수 없다. - 변수의 사용 변수 선언: int score; 값 저장: score = 90; 변수 선언과 동시에 할당: int price = 1000; - 변수 초기화 초기화란 변수에 값을 할당 하는것 // 변수는 초기화되어야 읽을 수 있다. int value; // 변수 선언 // System.out.p.. 2022. 9. 27.
반응형