자바_기초
배열 : 초기화 방법
잠수콩
2019. 5. 21. 15:24
// // 선언과 동시에 배열을 초기화하는 방법
// // 길이가 없는 배열 선언. 길이만큼 컴파일시 [] 안에 숫자가 들어간다.
// String str[] = new String[] {
// "I", "am", "hungry", "happy" //0, 1, 2, 3
// , "sing", "drive", "You", "are" //4, 5, 6, 7 총 8개
// };
// I am happy 출력
// You are hungry 출력
public class Array2_2 {
public static void main(String[] args) {
String str[] = new String[] {
"I", "am", "hungry", "happy"
,"sing", "drive", "You", "are"
};
// I am happy 출력
System.out.println(str[0] + " " + str[1] + " " + str[3]);
// You are hungry 출력
System.out.println(str[6] + " " + str[7] + " " + str[2]);
}
}