본문 바로가기

분류 전체보기218

ArrayList(2) package arrayLists; import java.util.ArrayList; public class ArrayList2 { public static void main(String[] args) { // ArrayList의 기능 ArrayList list = new ArrayList(); // .add(데이터); // - ArrayList에 데이터를 저장한다. - 배열과 같이 index(0)부터 저장된다. list.add("123"); list.add("456"); list.add("123"); list.add("789"); // .get(index); // - 해당하는 index에 담긴 데이터를 반환한다. System.out.println("list[0] : " + list.get(0)); Sy.. 2022. 7. 22.
ArrayList(1) package arrayLists; import java.util.ArrayList; public class ArrayList1 { public static void main(String[] args) { /* ArrayList - 배열과 같은 성질이다 - 데이터에 순서가 존재하며, 중복된 데이터 보관이 가능하다. Generic () - ArrayList선언 시 보관할 데이터들의 자료형을 지정할 수 있다. - 생략이 가능하며 이 경우에는 자료형Object로 데이터가 저장된다. -> Generic 생략시 그어지는 밑줄은 보관할 데이터들의 자료형에 대한 명시를 권고하는 의미다. * Object란? java의 최상위 class이며 모든 자료형의 데이터 수용이 가능하다. Wrapper Class (Generic.. 2022. 7. 22.
배열 예제(5) package arrays; import java.util.Scanner; public class Quiz10 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int bufSize = 3, dataInputCnt = 0; // bufSize - 배열의 크기, dataInputCnt - 현재 배열에 저장된 데이터 갯수 저장용도 int array[] = new int[bufSize]; while (true) { for (int cnt = bufSize - 3; cnt 이전까지 사용된 저장공간 그 이후부터 사용하기 위함. .. 2022. 7. 21.
배열 예제(4) package arrays; import java.util.Scanner; public class Quiz09 { public static void main(String[] args) { // Quiz // 건물층수, 각 층마다의 호수, 거주자의 이름을 입력받아 출력하는 코드 작성 Scanner sc = new Scanner(System.in); int floor, ho; System.out.println("===== 아파트 입주자 정보 ====="); while (true) { try { System.out.print("건물의 층수를 입력하세요 : "); floor = sc.nextInt(); } catch (Exception e) { System.out.println("잘못된 형식의 입력입니다...".. 2022. 7. 21.