Sunday, 12 March 2023

4. Write a program that accepts a string from command line and perform following operations: 1. Display each character on separate line in reverse order. 2. Count total number of chracters and display each character's position too. 3. Identify that whether the string is palindrom or not. 4. Count total number of uppercase and lowercase characters in it.

 



class Program4
{
    public static void main(String args[])
    {
        char arr[] = args[0].toCharArray();
        char temp[] = new char[arr.length];
        int flag=0;
       
        for(int i=arr.length-1; i>=0; i--)
        {
            System.out.println(arr[i]);
            temp[arr.length-1-i] = arr[i];
        }
       
        for(int i=0; i<arr.length; i++)
        {
            System.out.println(arr[i] + " character at " + i + " position");
        }
        System.out.println("total number of characters: " + arr.length);
       
        for(int i=0; i<arr.length; i++)
        {
            if(arr[i] == temp[i])
                flag++;
            //System.out.print(" " + flag);
        }
       
        if(flag == arr.length)
            System.out.println("\nString palindrom");
        else
            System.out.println("\nString is not palindrom");
       
        System.out.println("\nCount total number of uppercase and lowercase
characters in i: ");

        int up=0,lw=0;
        for(int i=0; i<arr.length; i++)
        {
            if(Character.isUpperCase(arr[i]))
                up++;
            else
                lw++;
        }
       
        System.out.println("\nupper case: " + up + "\nlower case: " + lw);
    }
}

No comments:

Post a Comment

python programs

1. sum of two number