본문 바로가기
반응형

전체 글200

[자바기초.028] for-each loop [자바기초.028] for-each loop 1.for-each 반복문(Enhanced for 반복문) 배열에 사용하면 좋을 for each loop(enhanced for loop)이 있습니다. for-each문은 그냥 일반적인 for문보다 사용하기 편합니다. for문의 index나 [ ] 괄호를 사용하지 않고 반복문 순회(traverse)를 할 수 있는게 for-each 문입니다. [예제1] 아래 코드는 String형, int 형 배열을 for-each loop으로 순회하며 요소값을 출력하는 코드입니다. HTML 삽입 미리보기할 수 없는 소스 for-each loop를 사용하면 배열의 첫 번째 요소(element)부터 마지막 요소까지 하나씩 자동적으로 접근할 수 있다. for-each loop를 사용.. 2024. 3. 29.
AP Computer Science A Java Quick Reference (3) Math Class AP Computer Science A Java Quick Reference (3) Math Class 자바에서 Math 클래스는 자바를 설치하면 포함되는 클래스로서, 이 클래스 안에 있는 메소드들은 static method이기 때문에 object를 만들지 않고 "클래스이름.메소드이름()" 방식으로 바로 사용가능합니다. Static methods (also called class methods) are called using the class name and the dot operator (.) followed by the method name. You do not need to create an object of the class to use them. You can use ClassName.metho.. 2024. 3. 28.
AP Computer Science A Java Quick Reference (2) Integer & Double AP Computer Science A Java Quick Reference (2) Integer & Double 1.Wrapper Class - Integer & Double HTML 삽입 미리보기할 수 없는 소스 wrapper class for int is Integer. wrapper class for double is Double. int, double의 primitive type 대신에 Integer, Double 같은 wrapper 클래스를 만들면 다양한 method를 사용할 수 있는 장점이 있습니다. Java 9 버전이후로는 그냥 = 연산을 사용하여 값을 바로 대입해 Integer, Double 오브젝트를 만들어도 됩니다. 생성자(Constructor)를 사용하여 Integer, Double.. 2024. 3. 28.
APCSA(JAVA) Midterm Test(Unit.01~05) APCSA(JAVA) Midterm Test(Unit.01~05) -Test link : Click this link 5.15. Midterm Test — AP CSAwesome 5.15. Midterm Test The following 20 questions are similar to what you might see on the AP CSA exam for Units 1 - 5. You may only take this test once while logged in. There are no time limits, but it will keep track of how much time you take. Click on the f runestone.academy [문제1] Which of the foll.. 2024. 3. 27.
[Java Class.10] this 키워드 [Java Class.10] this 키워드 1. this 키워드 this 키워드는 클래스 안에서 자기 자신의 object를 가리킬 때 사용합니다. [예제1] 아래 코드를 보며 this의 사용에 대해 이해해 보자. HTML 삽입 미리보기할 수 없는 소스 위 코드에서 this.name, this.email, this.phoneNumber라고 코딩한 부분은 사실 name, email, phoneNumber라고 그냥 코딩해도 되지만, "this.variable"형태로 굳이 코딩한 이유는 현재 object의 instance variable을 가리킨다는 것을 확실하게 구분하기 위해서 입니다. static method 안에서는 this, instance variable을 사용할 수 없습니다. 그 이유는 static.. 2024. 3. 26.
[자바기초.027] 변수 사용 범위(Scope & Access) [자바기초.027] 변수 사용 범위(Scope & Access) 1. 변수의 사용 범위 자바에서 변수를 만들 때, 변수의 사용 범위는 { } 로 정해진다. 자바에는 3가지 변수 범위(level of scope)가 있다. Class Level Scope for instance variables inside a class. Method Level Scope for local variables (including parameter variables) inside a method. Block Level Scope for loop variables and other local variables defined inside of blocks of code with { }. 지역 변수(Local variables)는 .. 2024. 3. 26.
[Java Class.09]Getters & Setters [Java Class.09]Getters & Setters 1. Getters / Accessors 클래스 안에 있는 instance variable(field)은 보통 private으로 선언하기 때문에, 이 intance variable에 접근하게 해주는 메소드(accessor or getter 메소드)를 public으로 만들어 주면 된다. getter 메소드의 return type은 instance variable의 type과 똑같다. [예제1-1] HTML 삽입 미리보기할 수 없는 소스 [예제1-2] HTML 삽입 미리보기할 수 없는 소스 [유제1] Try the following code. Note that it has a bug! It tries to access the private insta.. 2024. 3. 26.
AP Computer Science A Java Quick Reference AP Computer Science A Java Quick Reference (1) String Class APCSA 시험에서 자주 등장하는 Java method의 이론과 사용 방법에 대한 내용입니다. (1) String Class 자바에는 기본적으로 String 클래스가 존재합니다. String은 문자열을 의미하고, 문자열이란 문자(character)가 서로 연결된 형태("Hello")를 말합니다. String 클래스로 만든 object들은 String 클래스의 field와 method(위 표 참고)를 모두 사용할 수 있습니다. [예제1-1] 아래 코드의 실행 결과를 확인해 보세요. HTML 삽입 미리보기할 수 없는 소스 위 코드에서, greeting1, greeting2와 같이 "string lite.. 2024. 3. 25.
[자바AP연습문제]06.Arrays [자바AP연습문제]06.Arrays *06.Arrays에 대한 복습은 아래 "더보기" 클릭 더보기 An array is consecutive storage for multiple items of the same type like the top five scores in a game. You learned how to declare arrays, create them, and access array elements. Array elements are accessed using an index. The first element in an array is at index 0. Array - An array can hold many items (elements) of the same type. You can a.. 2024. 3. 24.
728x90
반응형