Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
TCS NQT Technical and Managerial Round Interview Questions

Program Discussion :: Basics

Home > Programs > Basics

9 / 265

Can you write a Palidrome program?

Answer:

import java.util.*;

public class strings {
    public static void main(String[] args) {

/*works for both numbers and strings*/
        String str,text1=" ";int s=0,c=0;
        Scanner sc=new Scanner(System.in);
        str=sc.nextLine();
        StringBuilder b = new StringBuilder(str);
        System.out.print(str.equals(b.reverse().toString())?"yes":"no");
    } 
    }
 

Asked In :: Tavant Technologies

Post Your Answer Here:

Language:

Post Your Reply Here: