package test;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Scanner;
public class Test {
public static void a(){
File srcFile = new File("D:/a.gif");
File dstFile = new File("D:/b.gif");
BufferedInputStream in =null;
BufferedOutputStream out =null;
try {
in = new BufferedInputStream(new FileInputStream(srcFile));
out = new BufferedOutputStream(new FileOutputStream(dstFile));
byte []b=new byte[10];
int len = -1;
while((len=in.read(b))!=-1){
out.write(b,0,len);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(in!=null){
try {
in.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (out!=null) {
try {
out.flush();
out.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
}
public static void main(String[] args) {
//a();
// TODO Auto-generated method stub
//从键盘上输入一个字符串str
String str="";
System.out.println("请输入一个字符串:");
Scanner in=new Scanner(System.in);
str=in.nextLine();
//根据字符串创建一个字符缓存类对象sb
StringBuffer sb=new StringBuffer(str);
//将字符缓存中的内容倒置
sb.reverse();
//计算出str与sb中对应位置字符相同的个数n
int n=0;
for(int i=0;i<str.length();i++){
if(str.charAt(i)==sb.charAt(i))
n++;
}
//如果所有字符都相等,即n的值等于str的长度,则str就是回文。
if(n==str.length())
System.out.println(str+"是回文!");
else
System.out.println(str+"不是回文!");
}
}