请高手看看这个程序有什么问题呀。
import java.io.*;
public class huiwen
{ public static void main(String args[])
throws IOException
{ String s; boolean flag;
int l,i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一行字符串:");
s=br.readLine(); l=s.length();
Judge judge=new Judge(s);
flag=judge.judgement(l,i);
if(flag) System.out.println("字符串+s+为回文");
else System.out.println("字符串+s+不是回文");
}
}
public class Judge
{ String str;
public boolean judgement(int w,int i)
{ boolean f;
if(w==0) {f=false; return f; }
if(w==1)
{f=true; return f; }
w=w-1;
if(str[w]!=str[i])
{ f=false;return f; }
else
while(w>i) judgement(w-1,i+1);
return f=true;
}
}
import java.io.*;
public class huiwen
{ public static void main(String args[])
throws IOException
{ String s; boolean flag;
int l,i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一行字符串:");
s=br.readLine(); l=s.length();
Judge judge=new Judge(s);
flag=judge.judgement(l,i);
if(flag) System.out.println("字符串+s+为回文");
else System.out.println("字符串+s+不是回文");
}
}
public class Judge
{ String str;
public boolean judgement(int w,int i)
{ boolean f;
if(w==0) {f=false; return f; }
if(w==1)
{f=true; return f; }
w=w-1;
if(str[w]!=str[i])
{ f=false;return f; }
else
while(w>i) judgement(w-1,i+1);
return f=true;
}
}
如果是按书上写的,还是好好看看。我帮你整理了一下import java.io.*;public class huiwen {
public static void main(String args[]) throws IOException {
String s;
boolean flag;
int l, i = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一行字符串:");
s = br.readLine();
l = s.length();
Judge judge = new Judge(); //Judge judge = new Judge(s); 没有参数构造器怎么传?
flag = judge.judgement(l, i);
if (flag)
System.out.println("字符串+s+为回文");
else
System.out.println("字符串+s+不是回文");
}
}class Judge {
String str; public boolean judgement(int w, int i) {
boolean f;
if (w == 0) {
f = false;
return f;
}
if (w == 1) {
f = true;
return f;
}
w = w - 1;
if (str[w] != str[i]) { //str又不是数组!
f = false;
return f;
} else
while (w > i)
judgement(w - 1, i + 1);
return f = true;
}
}
public class dddd
{ public static void main(String args[])
throws IOException
{ String s; boolean flag;
int l,i=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一行字符串:");
s=br.readLine();
l=s.length();
Judge judge=new Judge(s);
flag=judge.judgement(l,i);
if(flag) System.out.println("字符串+s+为回文");
else System.out.println("字符串+s+不是回文");
}
}
class Judge
{ String str;
public Judge(String s) {
str=s;
}
public boolean judgement(int w,int i)
{ boolean f;
if(w==0) {f=false; return f; }
if(w==1)
{f=true; return f; }
w=w-1;
if(str.charAt(w)!=str.charAt(i))
{ f=false;return f; }
else
if(w>i) judgement(w-1,i+1);
return f=true;
}
}