Question
I am trying to create this java program --my code-- import java.util.Scanner; public class Main { public static void main(String[] args) { // Create a
I am trying to create this java program
--my code--
import java.util.Scanner;
public class Main { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in);
// Prompt the user to enter a string System.out.print("Enter a string: "); String s = input.nextLine();
// The index of the first character in the string int low = 0;
// The index of the last character in the string int high = s.length() - 1;
boolean isPalindrome = true; while (low
low++; high--; }
if (isPalindrome){ System.out.println(s + " is a palindrome");} else if (!isPalindrome){ System.out.println(s + " is not a palindrome"); } else if (s == "0"){ System.out.println( " Thank you. "); } else { System.out.println( " wrong input "); }
} }
when I input a palindrome, it says not a palindrome. However, input 0 says it is a palindrome.
Is there any way to fix this?
Enter a string: 0 0 is a palindrome java -cp /tmp/DEFePV860B Main Enter a string: my gym my gym is not a palindromeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started