Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my code to see the word you type in is a pali Example pop is one. But i

ID: 3730601 • Letter: H

Question

Here is my code to see the word you type in is a pali Example pop is one. But i need help with case sensetive words for example whenever I type in Pop it comes out that it is not a pali

/*
* This Lab Is Used To Implement A Recursive Method To See If The Word Is A Pali
* Or Not
*/


package lab;
import java.util.*;

public class Lab4
{
//test method
public static void test()
{
int c=1;
Scanner sc =new Scanner(System.in);
String pali;


//Promt The User To Enter Pali With No White Spaces
while(c==1)
{
System.out.println("Please Insert A Word You'd Like To See If It Is A Palindrome! "
+ "(Please Do Not Use White Spaces Characters) Enter Nothing To Exit");
pali =sc.nextLine();


if(pali.length()==0)
{
break;   
}


if(check(pali))
{
System.out.println(pali + " Is A Palindrome!"
+ "");
System.out.println("");
}


else{
System.out.println(pali + " Is Not A Palindrome!");
System.out.println("");
}
}
}
  

//This Method Is Used To Check If It Is Pali   
public static boolean check(String pali)
{
if(pali.length()==0||pali.length()==1)
{
return true;   
}
if(pali.charAt(0)==pali.charAt(pali.length()-1))
{
return check(pali.substring(1,pali.length()-1));   
}
return false;
}
}

Explanation / Answer

/* * This Lab Is Used To Implement A Recursive Method To See If The Word Is A Pali * Or Not */ package lab; import java.util.*; public class Lab4 { //test method public static void test() { int c=1; Scanner sc =new Scanner(System.in); String pali; //Promt The User To Enter Pali With No White Spaces while(c==1) { System.out.println("Please Insert A Word You'd Like To See If It Is A Palindrome! " + "(Please Do Not Use White Spaces Characters) Enter Nothing To Exit"); pali =sc.nextLine(); if(pali.length()==0) { break; } if(check(pali)) { System.out.println(pali + " Is A Palindrome!" + ""); System.out.println(""); } else{ System.out.println(pali + " Is Not A Palindrome!"); System.out.println(""); } } } //This Method Is Used To Check If It Is Pali public static boolean check(String pali) { if(pali.length()==0||pali.length()==1) { return true; } // compare lower case version of the characters if(Character.toLowerCase(pali.charAt(0))==Character.toLowerCase(pali.charAt(pali.length()-1))) { return check(pali.substring(1,pali.length()-1)); } return false; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote