super 키워드는 부모 클래스의 생성자 호출
this 클래스는 자신의 생성자 호출
부모클래스는 상위클래스 또는 수퍼클래스
자식클래스는 하위클래스 또는 서브클래스
//기본 자료형 배열은 값을 안넣으면 모든 요소 0으로 초기화
int[] ar = new int[10]; //선언 객체생성
//인스턴스 배열(참조변수 배열)은 모든 요소 null로 초기화
String[] ar = new String[10];
int[] ar = {1,2,4}
String course[] = {"Java", "C++", "HTML5"};
int[] ar = {1, 2, 3, 4, 5};
//for(int i = 0; i < ar.length; i++) {
-> 이 문장을 아래와 같이 변경
for(int e : ar) {
System.out.println(e);
}
4 x 4의 2차원 배열을 만들고 이곳에 1에서 10까지 범위의 정수를 랜덤하게 생성하여 정수 16개를 배열에 저장하고, 2차원 배열을 화면에 출력하라.
8 6 1 1 7 3 6 9 4 5 3 7 9 6 3 1
public class Square {
public static void main (String[]args) {
int [][] arr = new int[4][4];
int num = 1;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = arr[i][j] = (int) (Math.random() * 10 + 1);
num++;
}
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
}
}
아래를 메모리 구조로 표현 하시오.
int[][] arr = new int[3][4]
2차원 배열의 행과 열의 크기를 사용자에게 직접 입력받되, 1~10사이 숫자가 아니면
“반드시 1~10 사이의 정수를 입력해야 합니다.” 출력 후 다시 정수를 받게 하세요.
크기가 정해진 이차원 배열 안에는 영어 대문자가 랜덤으로 들어가게 한 뒤 출력하세요.
(char형은 숫자를 더해서 문자를 표현할 수 있고 65는 A를 나타냄, 알파벳은 총 26글자)
import java.util.Scanner;
public class RandomSquare {
public static void main(String[] args) {
int row, col;
Scanner sc = new Scanner(System.in);
System.out.println("행 크기 : ");
row = sc.nextInt();
System.out.println("열 크기 : ");
col = sc.nextInt();
char [][] arr = new char[row][col];
for (row = 0; row < arr.length; row++) {
for ( col = 0; col < arr[row].length; col++) {
arr[row][col] = (char)(Math.random() * 26 + 65);
System.out.print(arr[row][col] + " ");
}
System.out.println();
}
}
}