posted by 준치 2008. 11. 25. 01:13
class StringSplit3
{
      public static void main(String[] args)
      {
            String str = "1,김천재,100,100,100,`2,박수재,95,80,90,`3,이자바,80,90,90,`4,소주섭,70,60,90,";

            String[] data = str.split("`");             // `를 구분자로 해서 문자열을 나눈다.
            String[] subData=null; 
            Student[] score = new Student[data.length];

            for(int i=0;i < data.length;i++) {
                  subData = data[i].split(",");       // , 를 구분자로 해서 문자열을 나눈다.
                  score[i] = new Student(subData[0],subData[1],subData[2],subData[3],subData[4]);
            }

            for(int i=0;i < score.length;i++) {
//                   System.out.println(score[i].toString()); 이문장과 아래문장은 같은 결과를 얻는다.
                  System.out.println(score[i]);
            }
      }
}

class Student
{
      String no="";
      String name="";
      String korean="";
      String english="";
      String math="";

      Student(String no, String name, String korean, String english, String math) {
            this.no = no;            
            this.name = name;            
            this.korean = korean;            
            this.english = english;            
            this.math = math;            
      }

      public String toString() {
            return "번호:" + no + ", 이름:" + name + ", 국어:" + korean + ", 영어:" + english + ", 수학:"+ math;
      }

}

/*
번호:1, 이름:김천재, 국어:100, 영어:100, 수학:100
번호:2, 이름:박수재, 국어:95, 영어:80, 수학:90
번호:3, 이름:이자바, 국어:80, 영어:90, 수학:90
번호:4, 이름:소주섭, 국어:70, 영어:60, 수학:90
*/

정보보안  민호쌤? 거기서 퍼옴 C#이랑 다를게 역시..없군.....