java↗3-6. 기본형과 참조형
1. 기본형 (Primitive type) -> 자바 개발자들이 정해놓은 틀 - 오직 8개 (boolean, char, byre, short, int, long, float, double) - 실제 값을 저장 2. 참조형 (Reference type) - 기본형을 제외한 나머지 (String, System 등) - 메모리 주소를 저장 (4 byte 또는 8 byte) Date today; // 참조형 변수 today를 선언 today = new Date(); // today에 객체의 주소를 저장
2024.03.12
no image
java↗3-5. 두 변수의 값 교환하기
int x = 10, y = 20; x = y; // y의 값을 x에 저장 y = x; // x의 값을 y에 저장 int x = 10, y = 20; int tmp; // 빈 컵 tmp = x; // x의 값을 tmp에 저장 x = y; // y의 값을 x에 저장 y = tmp; // tmp의 값을 y에 저장 public class VarEx5 { public static void main(String[] args) { int x = 20, y = 2; int tmp; tmp = x; // 1. x의 값을 tmp에 저장 x = y; // 2. y의 값을 x에 저장 y = tmp; // 3. tmp의 값을 y에 저장 System.out.println(x+"와규"+y); System.out.println("..
2024.03.12
no image
java↗3-4. 문자와 문자열
char ch = 'a'; char ch = 'AB'; // 에러 String s = "ABC"; 문자열 String s1 = "AB"; // String은 원래 클래스이다. 하지만, 자주써서 표기를 생략한다. String s2 = new String("AB"); String s = "A"; String s = ""; // 빈 문자열 char ch = ''; // 에러 String sl = "A" + "B"; // "AB" public class VarEx4 { public static void main(String[] args) { char ch = 'A'; int i = 'A'; // 값은 인수 'A'의 값이 나와 65가 나온다. String str = ""; String str2 = "ABCD"; ..
2024.03.12
no image
java↗3-3. 리터럴의 접두사와 접미사
public class VarEx3 { public static void main(String[] args) { final int score = 100; boolean power = true; byte b = 127; // -128~127 int oct = 010; // 8진수, 10진수로 8 int hex = 0x10; // 16진수, 10진수로 16 long l = 10_000_000_000L; // int는 20억까지 표기 가능 float f = 3.14f; double d = 3.14f; System.out.println(10.); // 10.0 System.out.println(.10); // 0.1 System.out.println(10f); // 10.0 System.out.println(1..
2024.03.12
no image
java↗3-2. 변수, 상수, 리터럴
변수(variable) - 하나의 값을 저장하기 위한 공간 (다른 값으로 몇 번이나 바꿀 수 있다) 상수(constant) - 한 번만 값을 저장 가능한 변수 (다른 값으로 바꿀 수 없다) 리터럴(literal) - 그 자체로 값을 의미하는 것 int score = 100; score = 200; final int MAX = 100; // MAX는 상수 MAX = 200; // 에러 public class VarEx2 { public static void main(String[] args) { final int score = 100; //score = 200; // final이 지정되어 있을 때 값을 더 주면은 오류가 뜬다. System.out.println(score); } }
2024.03.12
java↗3-1. 변수의 타입
1. 변수의 타입 변수의 타입은 저장할 값의 타입에 의해 결정된다. int = 5; char = "사랑" double = 5.14; 2. 값의 타입 (8개의 타입 = 기본형) - 문자 : char (character) - 숫자 (정수) : byte, short, int, long (실수) : float, double - 논리 : boolean (true or false)
2024.03.12
no image
java↗3. 변수
1. 변수(variable)란? 변하는 수? 하나의 값을 저장할 수 있는 메모리 공간 변수의 선언 이유 - 값(data)을 저장할 공간을 마련하기 위해서 2. 변수의 선언 방법 - 변수타입 변수이름; ex) int(정수 : integer) age; // 정수(int)타입의 변수 age를 선언 3. 변수에 값 저장하기 ('=' 는 등호가 아니라 대입) int age; // 정수(int)타입의 변수 age를 선언 age = 25; // 변수 age에 25를 저장 int age = 25; // 위의 두 줄을 한 줄로 변수의 초기화 - 변수에 처음으로 값을 저장하는 것 int x = 0; // 변수 x를 선언 후, 0으로 초기화 int y = 5; // 변수 y를 선언 후, 5로 초기화 int x = 0, y ..
2024.03.12
java↗2. 덧셈, 뺄셈
public class Ex2_1 { public static void main(String[] args) { //sysout ctrl+space 자동완성 //ctrl+alt+down 행단위 복사 //alt+shift+a 컬럼 편집 모드(토글) //print() - 출력 후에 줄바꿈을 안함 //println() - 출력 후에 줄바꿈을 합니다. System.out.println(3+5);// 덧셈 System.out.println(3-5);// 뺄셈 System.out.println(3*5);// 곱셈 System.out.println(3/5);// 나눗셈 } }
2024.03.11
java↗1. 단축키
public class Hello { public static void main(String[] args) { // ctrl+shitf+L 단축키 전체 목록보기 // ctrl+ +, - // ctrl+D 한 줄 삭제 // ctrl+alt+down 행단위 복사 // alt+shift+A 멀티컬럼 편집 // alt+up, down 행단위 이동 // ctrl+i 자동 들여쓰기 // ctrl+/ 주석 처리하기 // ctrl+space 자동완성 System.out.println(); System.out.println("Hello,world."); } }
2024.03.11