以下是我编写的程式,可是我自己也觉得不对.请大家指导: //fig.3-2: Test21.java //import javax.swing.JOptionPane;public class Test21 { public static void main (String args []) { String A,B,C,D,E; int a=0,b=0,c=0,d=0,e=0,total=0,gc=0;
//fig.3-2: Test21.java //import javax.swing.JOptionPane;public class Test21 { public static void main (String args []) { String A,B,C,D,E; int a=0,b=0,c=0,d=0,e=0,total=0,gc=0;
String str = "abcba"; StringBuffer s = new StringBuffer(); s.append(str); System.out.println(str.equals(s.reverse().toString())?"yes":"no");
以下为正确的答案: import javax.swing.JOptionPane;public class Test21 { public static void main (String args []) { String A,B,C,D,E; int a=0,b=0,c=0,d=0,e=0,total=0,gc=0;
//fig.3-2: Test21.java
//import javax.swing.JOptionPane;public class Test21 {
public static void main (String args []) {
String A,B,C,D,E; int a=0,b=0,c=0,d=0,e=0,total=0,gc=0;
while(gc!=-1){
A= JOptionPane.showInputDialog("A");
B= JOptionPane.showInputDialog("B");
C= JOptionPane.showInputDialog("C");
D= JOptionPane.showInputDialog("D");
E= JOptionPane.showInputDialog("E"); a= Integer.parseInt(A);
b= Integer.parseInt(B);
c= Integer.parseInt(C);
d= Integer.parseInt(D);
e= Integer.parseInt(E);
if(a=e){
if(b=d)
total= a*10000+b*1000+c*100+d*10+e*1;
System.out.println(total);
}
else
System.out.println("Wrong answer!");
gc+=1
}
}
}
//import javax.swing.JOptionPane;public class Test21 {
public static void main (String args []) {
String A,B,C,D,E; int a=0,b=0,c=0,d=0,e=0,total=0,gc=0;
while(gc!=-1){
A= JOptionPane.showInputDialog("A");
B= JOptionPane.showInputDialog("B");
C= JOptionPane.showInputDialog("C");
D= JOptionPane.showInputDialog("D");
E= JOptionPane.showInputDialog("E"); a= Integer.parseInt(A);
b= Integer.parseInt(B);
c= Integer.parseInt(C);
d= Integer.parseInt(D);
e= Integer.parseInt(E);
if(a=e){
if(b=d)
total= a*10000+b*1000+c*100+d*10+e*1;
System.out.println(total);
gc=-1;
}
else
System.out.println("Wrong answer!");
}
}
}
Test21.java:34: incompatible types
found : int
required: boolean
if(a=e){
^
Test21.java:34: incompatible types
found : int
required: boolean
if(b=d)
^
2 errors请问是什么原因?请指导.
http://community.csdn.net/Expert/TopicView.asp?id=3957171
String str = "abcba";
StringBuffer s = new StringBuffer();
s.append(str); System.out.println(str.equals(s.reverse().toString())?"yes":"no");
import javax.swing.JOptionPane;public class Test21 {
public static void main (String args []) {
String A,B,C,D,E; int a=0,b=0,c=0,d=0,e=0,total=0,gc=0;
while(gc!=-1){
A= JOptionPane.showInputDialog("A");
B= JOptionPane.showInputDialog("B");
C= JOptionPane.showInputDialog("C");
D= JOptionPane.showInputDialog("D");
E= JOptionPane.showInputDialog("E"); a= Integer.parseInt(A);
b= Integer.parseInt(B);
c= Integer.parseInt(C);
d= Integer.parseInt(D);
e= Integer.parseInt(E);
if(a==e){
if(b==d)
total= a*10000+b*1000+c*100+d*10+e*1;
System.out.println(total);
gc=-1;
}
else
System.out.println("Wrong answer!");
}
System.exit(0);
}}
import java.io.*;
public class TestPalindrome
{
public static boolean palindrome(char[] a,int used)
{
int i,k;
k=(int)(used+1)/2;
for(i=0;i<k;i++)
{
if(a[i]!=a[used-1-i])return false;
}
return true;
}
public static void compare()
{
String s=new String();
char[] c=new char[80];
int i,length,l,n=0;
boolean b;
BufferedReader input=new BufferedReader(new InputStreamReader
(System.in));
try
{
System.out.println("Input a string(less than 80
characters):");
s=input.readLine();
if(s.length()>80)
{
System.out.println("error:the number is out of
bound!");
System.exit(0);
}
}
catch(IOException e)
{
System.out.println(e);
}
//change upperletter to lowerletter
//s=s.toLowerCase();
length=s.length();
l=0;
for(i=0;i<length;i++)
{
if(s.charAt(i)==' ')
continue;
c[l]=s.charAt(i);
l+=1;
}
b=palindrome(c,l);
if(b)
System.out.println("The string is palindrome.");
else
System.out.println("The string is not palindrome.");
}
public static void main(String[] args)
{
compare();
char p='n';
BufferedReader input=new BufferedReader(new InputStreamReader
(System.in));
for(;;)
{
System.out.print("do you want to try again? Y/N ");
try
{
p=input.readLine().charAt(0);
}
catch(IOException e)
{
}
if((p=='y')||(p=='Y'))
compare();
else break;
}
}
}