【发布时间】:2014-03-03 03:55:42
【问题描述】:
我正在编写一个程序,该程序从用户那里获取一个单词,例如“banana”,将单词“b”的第一个字母像 ananab 一样放在末尾,然后检查它是否拼写相同的单词。我已经为此工作了几天,并尝试了几件事,但仍然不确定如何检查用户给出的字符串,其中一个字符串位于 for 循环中。到目前为止,这是我的程序。
public static void main(String[] args) {
System.out.println("Enter words that can be checked for backward spelling");
System.out.println("Please enter a word to check");
Scanner keyboard = new Scanner(System.in);
String words = keyboard.nextLine();
String firstLetter = String.valueOf(words.charAt(0));
String words2 = words.substring(1);
String otherwords = words2+firstLetter;
for (int i=otherwords.length()-1; i>=0; i--){
String newwords=String.valueOf(otherwords.charAt(i));
boolean match = newwords.equalsIgnoreCase(words);
if (match){
System.out.println("This word matches the criteria we are lookin for");}
}
}
}
【问题讨论】:
标签: java string for-loop compare