Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Character Array In Java, Char Array Program in Java:-

Char array is used to store char elements using proper sequence, it is basically used in String operation.


Syntax 

char arrayname[] = {'data1', 'data2', 'data3' }


Some Example of Char Array In Java:-



Palindrome Program in Java 

Pallindorm means from left to right and right to left string should be matched.

Pallindorm can be an integer as well as a string.

This program is used to check palindrome using String.

class Checkpallindrom
{

     public static void main(String args[])
     {
          char arr[] = {'m','a','d','a','n'};
          int i,j;
          boolean flag=true;
          for(i=0,j=arr.length-1;i<arr.length/2;i++,j--)
          {
                if(arr[i]!=arr[j])
                {
                    flag=false;
                    System.out.println("Not Pallindrom");
                    break;

                }

          }
         if(flag)
         System.out.println("Pallindrom");


     }


}

This program can be created by String also?

class ArrExample3
{
   public static void main(String args[])
   {
        String arr = "RAMAN";
        int i,j;
        for(i=0,j=arr.length()-1;i<arr.length()/2;i++,j--)
        {
               if(arr.charAt(i)!=arr.charAt(j))
               {
                   System.out.println("Not pallindrom");
                   break;
               }
        } 

        if(i==arr.length()/2)
         System.out.println("Pallindrom");

   }


}


Assignment of  Char Array and String Both?



Q)  WAP to convert Char Array From Upper Case Char to Lower Case Char?

Q)  WAP to find kth max char and kth min char?

Q)  WAP to count total numeric, alphabets, and special char in Char Array?

Q)  WAP to sort the char Array in descending order?

Q) WAP to convert char array to integer array?







2 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. Pallindrom program without using third variable?

    import java.util.Scanner;
    class Pallindrom
    {

    public static void main(String args[])
    {
    // char arr[] = {'d','a','m','a','n'};
    int i,j;
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter size of char array");
    char arr[] = new char[sc.nextInt()] ;
    for(i=0;i 'A'

    }
    for(i=0,j=arr.length-1 ; i<arr.length/2; i++,j--)
    {
    if(arr[i]!=arr[j])
    {
    System.out.println("NOT Pallindrom");
    break;
    }


    }
    if(i==arr.length/2)
    System.out.println("Pallindrom");

    }


    }

    ReplyDelete
  2. Program to check Pallindrom using String?
    import java.util.Scanner;
    class Pallindrom
    {

    public static void main(String args[])
    {

    int i,j;
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter String");
    String arr = sc.next();
    for(i=0,j=arr.length()-1 ; i<arr.length()/2; i++,j--)
    {
    if(arr.charAt(i)!=arr.charAt(j))
    {
    System.out.println("NOT Pallindrom");
    break;
    }


    }
    if(i==arr.length()/2)
    System.out.println("Pallindrom");

    }


    }

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post