import java.util.Arrays; public class App { public static void main(String[] args) throws Exception { int[] arr1; int arr2[]; int i, arr3[]; i =22; arr3 = new int[3]; int[] arr4 = new int[5]; for(int x = 0; x<5; x++){ System.out.println(arr4[x]); } arr4[0] = 22; System.out.println(Arrays.toString(arr4)); //arr4[5] = 55; arr4[4] = 44; System.out.println(Arrays.toString(arr4)); System.out.println(arr4.length); arr3 = new int[0]; System.out.println(Arrays.toString(arr3)); System.out.println(arr3.length); System.out.println(arr4[0] + "" + arr4[4]); String str = "abc"; char[] ch = new char[]{'a', 'b', 'c'}; System.out.println(str.length()); System.out.println(ch.length); arr1 = new int[3]; System.out.println(arr1); arr1 = new int[]{4, 3, 4, 5, 3}; System.out.println(arr1); arr1 = new int[]{1,2,3,4,5}; // arr2 = new int[5]; /* for(int x = 0; x<5; x++){ arr2[x] = arr1[x]; } */ // arr2 = Arrays.copyOfRange(arr1, 1, 3); // System.arraycopy(arr1, 1, arr2, 3, 2); arr2 = arr1.clone(); System.out.println(Arrays.toString(arr1)); System.out.println(Arrays.toString(arr2)); System.out.println(arr1); System.out.println(arr2); } }
import java.util.Arrays; import java.util.Scanner; public class App2 { public static void main(String[] args) { int[][] arr1; int[] arr2[]; int arr3[][]; arr1 = new int[4][3]; System.out.println(arr1); System.out.println(Arrays.toString(arr1)); //System.out.println(Arrays.toString(arr1[0])); for(int i=0; i<arr1.length; i++){ System.out.println(Arrays.toString(arr1[i])); } arr2 = new int[3][]; arr2[0] = new int[3]; arr2[1] = new int[5]; arr2[2] = new int[4]; for(int i=0; i<arr2.length; i++){ System.out.println(Arrays.toString(arr2[i])); } System.out.println("----------"); Scanner sc = new Scanner(System.in); int x = sc.nextInt(); arr3 = new int[x][]; for(int i=0; i<arr3.length; i++){ arr3[i] = new int[sc.nextInt()]; } for(int i=0; i<arr3.length; i++){ System.out.println(Arrays.toString(arr3[i])); } sc.close(); } }
import java.util.Arrays; import java.util.Scanner; public class App3 { public static void main(String[] args) { Tv.model(); Tv tv1 = new Tv(); tv1.changeChannel(22); tv1.currentChannel(); tv1.changeChannel("33"); tv1.currentChannel(); } } class Tv{ String color; boolean power; int channel; static int modelNum = 2022; void power(){ power = !power; } void currentChannel(){ System.out.println("현재 채널: " + channel); } void changeChannel(int channel){ this.channel = channel; } void changeChannel(String channel){ this.channel = Integer.parseInt(channel); } static void model(){ System.out.println("모델명: " + modelNum); } static void change(int a){ modelNum += a; } }