好的。我查看了如何製作迴文,看起來像使用reverse()方法似乎是我最好的選擇。但是,在我的代碼中,我遇到了一個我不明白的錯誤。在Java中使用reverse()命令?
import java.util.*;
public class retreiveInput
{
private Scanner input = new Scanner(System.in);
private int fives = 0;
public retreiveInput(){
fives = input.nextInt();
}
public void check()
{
while(fives < 9999 || fives > 100000)
{
System.out.println("The number does not work! It is NOT 5 digits!");
fives = input.nextInt();
}
String five = Integer.toString(fives);
five.equalsIgnoreCase(new StringBuilder(five).reverse().toString());
if(five = five.reverse()){
}
}
}
在代碼的反向,它給我以下錯誤。 「方法reverse()未定義類型字符串」
任何想法如何解決這個問題?程序應該做的是,在if語句的reverse()點,程序應該檢查5的值是否等於5的倒數。
該字符串類沒有reverse()方法,但StringBuilder確實 –
那麼我將如何去使用StringBuilder來修復if語句? – user3348422
@LuiggiMendoza我想錯誤是在'five.reverse()'。 '五'是類型字符串 –