我正在练习制作自己的String逆转工具.我在一个简单的应用程序中使用该方法的学习过程.但是..
当我在Eclipse中运行我的代码时,即使word = = racecar并且反转变为= racecar(单词反转).显示了其他的东西..告诉我这个词和反向永远不会相等......但是......那个案子是什么?对?请给我一些建议,这真是太无聊了.谢谢.
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args){
System.out.println("Please enter a word, I'll show it reversed ");
System.out.println("and tell you if it is read the same forward and backward(A Palindrome)!: ");
String word = sc.nextLine();
String reverse = reverse(word);
if (reverse == word){
System.out.println("Your word: " + word + " backwards is " + reverse + ".");
System.out.println("Your word is read the same forward and …Run Code Online (Sandbox Code Playgroud)