자바하다가 막히는 부분이 있어서 그런데요 책에있는 소스를 그대로 옮겨서 쳐볼게요
이해안되는부분은 굵은색으로 글씨를 쳐드릴게요
이쁜사진이나 뭐 그런거 잇어야할것같은데..
알려주시면 이은혜 잊지않을게요 ㅠㅠ..
전체적으로는 전화번호부 관련된 것인데요
여기서 case 1,2,4는 이해갓는데요
유독 3번이 이해가 잘 안가네요 ..
데이터를 삭제하고 막 땡기고 뭐하고 하는 부분인줄은 알겟는데 도통 잘 이해가 가지가않아서요..
저기 굵은색부분이 이해가 잘 가지가 않아요 .
그리고 compareto 는 두개를 비교해서 똑같아서 idx를 반환해서 idx값이 0인데
그 0을 deletedata메소드에서 초기값으로 설정해주는것 까지는 알겟는데
그 다음의 조건값에서.. idx<(curcnt-1)
이부분이 잘 이해가가지가 않아요..
저렇게된다면 idx값이 0인데 curcnt값이 return문에 받아서 1값이 됫는데 거기서 다시1을 빼버리면
for(idx =0 ; idx < 0 ; idx++)
이렇게되서 실행이 안되는데..;;;


말이 너무 어렵지만 꼭 도움을 주세요 ㅠㅠ..
계속게속 보고잇을테니까 꼭 구원의 손길을 주세요 부탁드립니다 ..(__)

-------------------------------------------------------------------------------------------------
import java.util.Scanner;

public class phonebookver03
{
 public static void main(String args[])
 {
  phonebookmanager manager = new phonebookmanager();
  int choice;
  
  while(true)
  {
   showof.showofshow();
   choice = showof.keyboard.nextInt();
   showof.keyboard.nextLine();
   
   switch(choice)
   {
   case 1:
    manager.inputdata();
    break;
    
   case 2:
    manager.search();
    break;
   
   case 3:
    manager.deletedata();
    break;
   
   case 4:
    System.out.println("프로그램 종료 ");
    return;
   }
  }
 }
}

class phoneinfo
{
 String namename;
 String phonephone;
 String birthbirth;
 
 public phoneinfo(String named,String phonenum,String birthday)
 {
  namename = named;
  phonephone = phonenum;
  birthbirth = birthday;   
 }
 
 public phoneinfo(String named,String phonenum)
 {
  namename = named;
  phonephone = phonenum;
  birthbirth = null;
 }
 
 public void showofresult()
 {
  System.out.println("이름 " + namename); 
  System.out.println("핸드폰번호  : " + phonephone);
  if(birthbirth != null)
  {
   System.out.print("생일 " + birthbirth);
  }
  else
  {
   System.out.print("생일이 없다 ");
  }  
 }
}


class phonebookmanager
{
 final int max_cnt = 100;
 int curcnt = 0;
 phoneinfo[] infomaster = new phoneinfo[max_cnt];
 
 public void inputdata()
 {
  System.out.println("데이터 입력을 시작합니다.. ");
  System.out.print("이름 : ");
  String name = showof.keyboard.nextLine();
  System.out.print("전화번호 : ");
  String phone = showof.keyboard.nextLine();
  System.out.print("생년월일 : ");
  String birth = showof.keyboard.nextLine();
  
  infomaster[curcnt++] = new phoneinfo(name,phone,birth);
  System.out.println("데이터 입력이 완료되었습니다 ");
 }
 
 public void search()
 {
  System.out.println("데이터 검색을 시작합니다 ");
  System.out.print("이름 : ");
  String name = showof.keyboard.nextLine();
  
  int dataindex = search(name);
  
  if(dataindex<0)
  {
   System.out.println("해당 데이터가 존재하지 않습니다 ");
  }
  else
  {
   infomaster[dataindex].showofresult();
   System.out.println("데이터 검색이 완료되었습니다 ");
  }
 }
 
 private int search(String name)
 {
  
  for(int idx = 0; idx<curcnt; idx++)
  {
   phoneinfo curinfo = infomaster[idx];
   
   if(name.compareTo(curinfo.namename)==0)
    return idx;
  }
  return -1;
 }
 
 public void deletedata()
 {
  System.out.println("데이터 삭제를 시작합니다 ... ");
  
  System.out.print("이름 : ");
  String Name = showof.keyboard.nextLine();
  
  int dataidx = search(Name);
  
  if(dataidx<0)
   System.out.println("해당하는 데이터의 존재하지않는다 ");
  else
  {
   for(int idx = dataidx; idx<curcnt-1;idx++)
    infomaster[idx] = infomaster[idx+1];
   
   curcnt --;
   System.out.println("해당 데이터의 삭제가 완료되었습니다 ");
  }
  
 }
}


class showof
{
 public static Scanner keyboard = new Scanner(System.in);
 public static void showofshow()
 {
  System.out.println("1. 데이터 입력 ");
  System.out.println("2. 데이터 검색 ");
  System.out.println("3. 데이터 삭제 ");
  System.out.println("4. 프로그램 종료 ");
  System.out.print("선택 : ");
 }
}