Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions