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

I am trying to create this java program --my code-- import java.util.Scanner;

--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.

public class Main { public static void main(String[] args) { // Create

a Scanner Scanner input = new Scanner(System.in); // Prompt the user to

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 palindrome

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!