close

判斷是否為迴文

 

 

import java.io.*;


    public class abcde
    {
   
     public static void main(String args[]) throws IOException
    {
     String  OutFileName;
     FileReader inputjerry=new FileReader("940301.SM");
     BufferedReader binputjerry=new BufferedReader(inputjerry);
     //System.out.print("(迴文判斷)請輸入字母或數字:");
     String s1=binputjerry.readLine();
     String s2="";
     for (int i=s1.length();i>0;i--){
      char ch =s1.charAt(i-1);
      s2=s2+ch;
     OutFileName = "940301.SM1" ;
     File myfile=new File(OutFileName);
     myfile.createNewFile();

    FileOutputStream fos = new FileOutputStream(myfile);
    PrintStream ps = new PrintStream (fos);
 
   if (s1.equals(s2)) ps.print(s1+"  是迴文");
   else  ps.print(s1+"  非迴文");

}
     if (s1.equals(s2)) System.out.println(s1+"  是迴文");
     else System.out.println(s1+"  非迴文"); 
    }
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 ann9999963 的頭像
    ann9999963

    pon~pon~部落閣

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