Knowee
Questions
Features
Study Tools

You are provided with a code to find if a given string is a palindrome or not.The code is shuffled.  Rearrange the code in the correct order.System.out.println(str+" is not a Palindrome");import java.util.Scanner;StringBuffer sb = new StringBuffer(str);public static void main(String[] args) {Scanner sc=new Scanner(System.in);public class Main {elseString str=sc.next();sb.reverse();if(str.equalsIgnoreCase(reverse))   }}System.out.println(str+" is a Palindrome");String reverse=sb.toString();

Question

You are provided with a code to find if a given string is a palindrome or not.The code is shuffled.  Rearrange the code in the correct order.System.out.println(str+" is not a Palindrome");import java.util.Scanner;StringBuffer sb = new StringBuffer(str);public static void main(String[] args) {Scanner sc=new Scanner(System.in);public class Main {elseString str=sc.next();sb.reverse();if(str.equalsIgnoreCase(reverse))   }}System.out.println(str+" is a Palindrome");String reverse=sb.toString();

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is the rearranged code:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        StringBuffer sb = new StringBuffer(str);
        sb.reverse();
        String reverse = sb.toString();
        if(str.equalsIgnoreCase(reverse)) {
            System.out.println(str + " is a Palindrome");
        } else {
            System.out.println(str + " is not a Palindrome");
        }
    }
}

This Java code checks if a given string is a palindrome or not. It reads a string from the user, reverses it, and then compares the reversed string with the original one. If they are equal, it prints that the string is a palindrome. Otherwise, it prints that the string is not a palindrome.

This problem has been solved

Similar Questions

class Solution { public boolean isPalindrome(int x) { String num =Integer.toString(x); for(int i=num.length()-1;i<0;i--){ String a =" "+num; if(num==a){ System.out.println("it is palindrome:"+a); }else{ System.out.println("it is not palindrome:"+a); } } }}

Write a Java program to check whether a given word is a palindrome or not. for e.g. MADAM is a palindrome but eat is not.

Write a python program to check the given string is palindrome or not.

Write a C++ program to check if a given number is a palindrome. A palindrome is a number that remains the same when its digits are reversed.

Check Palindrome NumberWrite a program to check if the given number is a palindrome number.A palindrome number is a number that is the same after reverse. For example, 545, is the palindrome numbers

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.