/** * @(#)test.java * @title: 判斷是否為對稱? * @note: sample for eyny's user * @author: Arthur Liu * @version: 1.00 2009/10/21 */ import java.io.*; public class test { public test() { } public static void main(String[] args) throws IOException { System.out.println("請輸入字串:"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String str1 = br.readLine(); String str2 = new StringBuffer(str1).reverse().toString(); if (str1.equals(str2)) System.out.println("對稱字串"); else System.out.println("非對稱字串"); } }
--------------------Configuration: <Default>--------------------
請輸入字串:
12321
對稱字串
Process completed.
全站熱搜
留言列表