d014: 2006 程式達人 A - Square the World  

d014: 2006 程式達人 A - Square the World  

=======================================================main

import java.util.Scanner;


public class main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner scan =new Scanner(System.in);
        int count;
        System.out.println("Please enter 次數:");
        count=scan.nextInt();
        for(int x=0;x<count;x++){
            System.out.println("Please enter string :");
            String input=scan.next();
            Square s=new Square();
            s.SquareMethod(input);
            System.out.println();
        }
        
    }

}

=======================================================Square.java

import java.util.ArrayList;


public class Square {
    public void SquareMethod(String scanStr){
        ArrayList<Character> arrayStr =new ArrayList<Character>();
        for(int count=0;count<scanStr.length();count++){
            arrayStr.add(scanStr.charAt(count));
        }
        System.out.println(scanStr);
        for(int count=1;count<arrayStr.size()-1;count++){
            System.out.print(arrayStr.get(count));
            for(int x=1;x<=scanStr.length()-2;x++){
                System.out.print(" ");
            }
            System.out.println(arrayStr.get(arrayStr.size()-count-1));
            
        }
        for(int x=arrayStr.size()-1;x>=0;x--){
            System.out.print(arrayStr.get(x));
        }
        
    }

}

,
創作者介紹

Mazs's Notes

cookiesp 發表在 痞客邦 PIXNET 留言(0) 人氣()