Question__1

PHOTO EMBED

Tue Apr 18 2023 18:34:07 GMT+0000 (Coordinated Universal Time)

Saved by @Mohamedshariif #java

import java.util.Scanner;
public class Lab_5 {

    public static void main(String[] args) {
        
/*Question 1. Write a program that prompts the user to enter a string 
        and determines whether it is a palindrome string. 
        A string is palindrome if it reads the same 
        from right to left and from left to right. */
                
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a string:");
        String str = scanner.nextLine();
        
        int count = 0;
        for(int counter =0; counter < str.length(); counter++)
        {
            if(str.charAt(counter)==str.charAt(str.length()-1-counter))
                count = count + 1;
        }
        
        if( count == str.length())
        {
            System.out.println("The string " + str + " is palindrome");
        }
        else
        {
            System.out.println("The string " + str + " is not palindrome");
        }
    }
}
content_copyCOPY