Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Checking String is a Palindrome or Not..

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 342
    Comment on it

    STRING :

    Strings are a sequence of characters used in programming. In the Java programming language, strings are defined as objects.

    The Java platform provides the String class to create and manipulate strings.

    Creating Strings:

    The most common way to create a string is to write:

    String greeting = " ";

    or String name ="deepak";

    String Length:

    Methods used to obtain information about an object are known as accessor methods. One accessor method that you can use with strings is the length() method, which returns the number of characters contained in the string object The following program illustrate the use of String using String Functions. This program make use of following functions:
    1. int compareTo(String anotherString) : Compares two strings lexicographically.
    2.int (string)length() :Returns the number of characters contained in the string object

    Checking whether the input String is Palindrome or not...
    import java.io.*;
    import java.util.Scanner;
    
    class Hello{
    
       public static void main(String args[])throws Exception {
    
        Scanner sc = new Scanner(System.in);
              System.out.println("Enter the String ");
              String s=sc.next();
              String p="";
              int m=s.length();
              for(int i=m-1;i>=0;i--) {
            char c = s.charAt(i);
                  p= p + c;
              }
              if(s.compareTo(p)==0)
              {
                  System.out.println("Its palindrome");
              }
              else
                  System.out.println("Not a palindrome");
    
           }
    }
    
    Output:
    Enter the String :Madam
    Its is Palindrome
    
    Strings in java

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: