古い詩を縦に並べて右から左へ読む

1782 ワード

import java.util.ArrayList;   
  
public class GuShi {   
    public static void main(String[] args) {   
  
        String[] src = new String[] { " ,", " 。", " ,", " 。" };   
        ArrayList list = new ArrayList();   
        int maxlen = 0;   
        for (int i = 0; i < src.length; i++) {   
            StringBuffer buffer = new StringBuffer();   
            if (src[i] != null && src[i].length() > 0) {   
                buffer.append(src[i]);   
                if (maxlen < src[i].length()) {//     
                    maxlen = src[i].length();   
                }   
            } else {   
                buffer.append("");   
            }   
            list.add(buffer);   
        }   
  
        //     
        ArrayList result = new ArrayList();   
        for (int i = 0; i < maxlen; i++) {   
            StringBuffer buffer = new StringBuffer();   
            for (int j = 0; j < list.size(); j++) {   
                StringBuffer tmp = (StringBuffer) list.get(j);   
                if (i >= tmp.length()) {   
                    buffer.append(" ");   
                } else {   
                    buffer.append(tmp.charAt(i) + " ");   
                }   
            }   
            result.add(buffer.toString());   
        }   
        //  result ,    
        for (int i = 0; i < result.size(); i++) {   
            System.out.println(result.get(i).toString());   
        }   
  
    }   
  
}