'Array'에 해당되는 글 1건
[04.16] 수업 내용 :: 2007/04/16 11:32
1. Array - Exam1
소스 보기
2. Array - Exam2
more..
3. Array - Exam3
more..
4. Array - Exam4
이차원 배열
more..
5. Array - Exam5
배열의 동적 생성
more..

| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
1. Array - Exam1
소스 보기
public class Exam_03 {
public static void main(String ... args) {
short[] x = {3, 6, 3, 4, 7, 8, 4, 3};
System.out.printf("x.length = %d\n", x.length);
for(int i = 0 ; i < x.length ; i++)
System.out.printf("x[%d] = %d\n", i, x[i]);
}
}
2. Array - Exam2
more..
public class Exam_04 {
public static void main(String[] args) {
int [] x = new int[5];
boolean [] y = new boolean[3];
for(int i = 0 ; i < x.length ; i++)
System.out.printf("x[%d]=%d\n", i, x[i]);
for(int i = 0 ; i < y.length ; i++)
System.out.printf("y[%d]=%b\n", i, y[i]);
}
}
3. Array - Exam3
more..
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class Exam_04 {
public static void main(String[] args) throws IOException {
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader bs = new BufferedReader(is);
Random r = new Random();
System.out.printf("생성할 배열의 크기를 지정해주세요 :");
int num = Integer.parseInt(bs.readLine());
int [] x = new int[num];
// 배열 갯수 미만의 랜덤 값을 넣는다.
for(int i = 0 ; i < x.length ; i++)
x[i] = r.nextInt(num);
for(int i = 0 ; i < x.length ; i++)
System.out.printf("x[%d]=%d\n", i, x[i]);
}
}
4. Array - Exam4
이차원 배열
more..
public class Exam_14 {
public static void main(String[] args) {
int [][] a = new int[3][2];
for(int i = 0 ; i < a.length ; i++)
for(int j = 0 ; j < a[i].length ; j++)
System.out.printf("a[%d][%d] = %d\n", i, j, a[i][j]);
}
}
5. Array - Exam5
배열의 동적 생성
more..
import java.util.Random;
public class Exam_14_1 {
public static void main(String[] args) {
Random r = new Random();
int[][] a = new int[3][];
for(int i = 0 ; i < a.length ; i++)
a[i] = new int[r.nextInt(5)];
for(int i = 0 ; i < a.length ; i++) {
System.out.printf("a[%d]의 길이 : %d\n", i, a[i].length);
for(int j = 0 ; j < a[i].length ; j++)
System.out.printf("a[%d][%d]=%d\n", i, j, a[i][j]);
}
}
}