갑자기 시험을 본다고 함. 자바 배열에 대해서 오전에 수업을 하고 오후에 시험을 본다. 나는 아는 것이 없는데 결과는 뻔하다. 이해하지 못한 파트다. 결과물을 만들어 낼 수 없을 것이다. 찾아서라도 어디서 구글링을 해서라도 해낼 수 있을까? 난 이해가 없는 상태지만 그냥 해보자.
Integer[] 무슨 뜻이지?
public int 무슨 뜻인가?
배열을 한다는데 뭘 한다는 거야
new는 왜 붙이는거지? 지금 뭘 하려는 거지? 답답하네 정말.
count = 0; 이건 뭔데
ARRAY_SIZE = size; ?????
자바의 정석 독학을 해보자. 강의를 듣던 뭘 해야 따라갈 수 있고 실력이 늘 것이다.
for 문을 써보라는데 for문이 뭔지를 모르겠다.
오늘도 못 따라가고 있다. 오후에 시험을 본다는데 무책임하다. 나만 못 따라가는 것인가?
분노가 끓어오르고 있다.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
배열 테스트 배열배열배열배열배열배열배열배열
자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자. 자바의 정석 독학을 해보자.
물어보면서 해야겠다. 나 말고도 모르는 사람 많음. 진도가 빠른 것이 사실이다.
문제가 나왔는데 손도 못대겠다. 나는 아는 것이 없다. 그래도 해냈다. 구글 검색으로 찾아냄.
package kr.co.ezenac;
public class EzenArray {
int[] intArr; //int array
int count; //개수
public int ARRAY_SIZE;
public static final int ERROR_NUM = -999999999;
public EzenArray()
{
count = 0;
ARRAY_SIZE = 10;
intArr = new int[ARRAY_SIZE];
}
public EzenArray(int size)
{
count = 0;
ARRAY_SIZE = size;
intArr = new int[size];
}
public void addElement(int num) //추가
{
if(count >= ARRAY_SIZE){
System.out.println("not enough memory");
return;
}
intArr[count++] = num;
}
public void insertElement(int position, int num) //특정위치에 추가
{
int i;
if(count >= ARRAY_SIZE){ //꽉 찬 경우
System.out.println("not enough memory");
return;
}
if(position < 0 || position > count ){ //index error
System.out.println("insert Error");
return;
}
for( i = count-1; i >= position ; i--){
intArr[i+1] = intArr[i]; // 하나씩 이동
}
intArr[position] = num;
count++;
}
public int removeElement(int position) //특정요소삭제
{
int ret = ERROR_NUM;
if( isEmpty() ){
System.out.println("There is no element");
return ret;
}
if(position < 0 || position >= count ){ //index error
System.out.println("remove Error");
return ret;
}
ret = intArr[position];
for(int i = position; i<count -1; i++ )
{
intArr[i] = intArr[i+1];
}
count--;
return ret;
}
public int getSize() //사이즈값 확인
{
return count;
}
public boolean isEmpty()
{
if(count == 0){
return true;
}
else return false;
}
public int getElement(int position) //특정위치 요소 읽기
{
if(position < 0 || position > count-1){
System.out.println("검색 위치 오류. 현재 리스트의 개수는 " + count +"개 입니다.");
return ERROR_NUM;
}
return intArr[position];
}
public void printAll() //출력
{
if(count == 0){
System.out.println("출력할 내용이 없습니다.");
return;
}
for(int i=0; i<count; i++){
System.out.println(intArr[i]);
}
}
public void removeAll() //모두 삭제
{
for(int i=0; i<count; i++){
intArr[i] = 0;
}
count = 0;
}
}
---------------------------------------------------
package kr.co.ezenac;
public class EzenArrayTest {
public static void main(String[] args) {
EzenArray array = new EzenArray ();
array.addElement(10);
array.addElement(20);
array.addElement(30);
array.printAll();
System.out.println("===============");
array.insertElement(1, 50);
array.printAll();
System.out.println("===============");
array.removeElement(1);
array.printAll();
System.out.println("===============");
array.addElement(70);
array.printAll();
System.out.println("===============");
array.removeElement(1);
array.printAll();
System.out.println("===============");
System.out.println(array.getElement(2));
System.out.println("===============");
array.removeAll();
array.printAll();
}
}
어쨋든 문제해결하면 됐어. 해냈다는 것이 중요함.
'코딩 학원(국비지원)' 카테고리의 다른 글
13일차 코딩학원 (0) | 2023.02.06 |
---|---|
생활코딩 - 문자열 다루기 / 자바의 정석 - JVM이란 (0) | 2023.02.06 |
데이터란 무엇인가 (0) | 2023.02.03 |
스스로 학습해야 된다 (0) | 2023.02.02 |
11일 차 코딩 수업 (0) | 2023.02.02 |