Given the code fragment: public class Arr67 { public static void main(String[] args) { int[] stack={10,20,30}; int size=3; int idx=0; /* line n1 */ System.out.print("The Top element: "+stack[idx]); } } Which code fragment, inserted at line n1, prints The Top element: 30? A. do{ idx++; System.out.println("idx: "+idx); }while(idx>=size); B. while(idx

배열이란 동일한 자료형으로 선언된 데이터 공간을 메모리 상에 연속적으로 나열하여 데이터 관리의 효율성을 높이는 것입니다. 변수는 한개의 데이터만 저장할 수 있습니다. 따라서 저장해야 할 데이터의 수가 많아지면 그만큼 많은 양의 변수를 선언해줘야하는 비효율성이 발생하죠. 그렇기에 좀 더 효율적인 방법이 필요한데 이것이 배열입니다. 배열은 같은 타입의 데이터를 연속된 공간에 나열시키고 각 데이터에 인덱스(index)를 부여해 놓은 자료구조입니다. 여러가지 배열 선언 //int 타입 배열 선언 int[] i_array; int i_array[]; //배열 생성후 초기화하면 배열의 주소가 할당된다. int[] i_array = new int[8]; //초기값 0 String[] s_array = new Stri..
Given the code fragment: import java.util.ArrayList; public class List63 { public static void main(String[] args) { ArrayList points = new ArrayList(); points.add(1); points.add(2); points.add(3); points.add(4); points.add(null); points.remove(2); points.remove(null); System.out.println(points); } } What is the result? A. A NullPointerException is thrown at runtime. B. [1,2,4] C. [1,2,4,null] D...
Given: public class Product{ int id; String name; public Product(int id, String name){ this.id=id; this.name=name; } } public class Class47 { public static void main(String[] args) { Product p1=new Product(101,"Pen"); Product p2=new Product(101,"Pen"); Product p3=p1; boolean ans1=p1==p2; boolean ans2=p1.name.equals(p2.name); System.out.print(ans1 + ":" + ans2); } } What is the result? A. true:tr..
Given the code fragment: import java.util.ArrayList; import java.util.List; public class List81 { public static void main(String[] args) { List colors=new ArrayList(); colors.add("green"); colors.add("red"); colors.add("blue"); colors.add("yellow"); colors.remove(2); colors.add(3,"cyan"); System.out.println(colors); } } What is the result? A. (green,red,yellow,cyan) B. (green,blue,yellow,cyan) C..
Given: public class Type43 { static double area; int b=2, h=3; public static void main(String[] args) { double p,b,h; //line n1 if(area==0){ b=3; h=4; p=0.5; } area=p*b*h; //line n2 System.out.println("Area is "+area); } } What is the result? A. Area is 6.0 B. Area is 3.0 C. Compilation fails at line n1 D. Compilation fails at line n2 정답: D 변수들 (p,b,h)이 초기화가 되지 않았는데 계산을 하려고 해서 컴파일 에러가 난다. 마치 if ..

ocajp에는 2차월 배열 문제가 많이 나온다. 그래서 자바 2차원 배열에 관해 정확히 이해하고 가는게 좋다. 2차원 배열에 대해 알려드릴게요. 바로 이전 포스팅에서 보셨던 배열이 1차원 배열이에요. 2차원 배열은 값을 더 많이 효과적으로 담을 수 있어요. 이런 2차원 이상의 배열을 다차원 배열이라고 하는데 실질적으로 2차원 배열 이상으로는 잘 사용되지 않아요. 1차원과 2차원이 무엇이냐면 1차원 배열에서는 값을 1번만 담아요. 그런데 2차원 배열은 1차원 배열에 값을 더 담을 수 있어요. 예를 들어볼게요. int[][] arr = new int[3][4]; 3개의 배열 안에 각각 4개씩 더 담을 수 있는 거죠. 이것을 보기 쉽게 변경한다면 이런 형태가 돼요. 따라서 int[3][4]이면 3은 세로 길이..
Given class Base{ public void test() { System.out.println("Base "); } } class DerivedA extends Base{ public void test() { System.out.println("DerivedA "); } } class DerivedB extends DerivedA { public void test() { System.out.println("DerivedB "); } public static void main(String[] args) { Base b1=new DerivedB(); Base b2=new DerivedA(); Base b3=new DerivedB(); b1=(Base)b3; Base b4=(DerivedA)b3; b..
- Total
- Today
- Yesterday
- XE
- C언어
- 플러터
- XE3
- KG
- Python
- 파싱
- xe애드온
- 라이믹스 모듈
- esql
- 포인터
- 파이썬
- 오라클
- php
- 스크래핑
- EC
- 이클립스
- 프로씨
- 문자열
- 인포믹스
- JDBC
- xe addon
- MySQL
- webix
- ocjap
- ocajp
- 자바 smtp
- proc
- C
- 자바
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |