English

Write a program for the following. Input a string to display these patterns. Assume the string is "CALENDAR" Radnelac Adnelac Dnelac Nelac Elac Lac Ac C

Advertisements
Advertisements

Question

Write a program for the following.

Input a string to display these patterns. Assume the string is "CALENDAR"

Radnelac
Adnelac
Dnelac
Nelac
Elac
Lac
Ac
C
Code Writing
Advertisements

Solution

import java.util.*;
class clTask
{
      void main()
      {
           String s1 = "", s2 = "";
           Scanner sc = new Scanner(System.in);
           System.out.print(" Entera sentence : ");
           s1 = sc.nextLine();
           int len = s1.length();
           for(int j = len - 1; j >= 0; j--)
           {
              s2 = s2 + s1.charAt(j);
           }
           for(int j = 0; j <= len – 1; j++)
           {
              for(int k = 0; k <= j; k++)
              {
                  System.out.print(" ");
              }
              System.out.println(s2.substring(j));
           }
      }
}

Output:

Enter a sentence : CALENDAR

RADNELAC

ADNELAC

DNELAC

NELAC

ELAC

LAC

AC

C

shaalaa.com
  Is there an error in this question or solution?
Chapter 10: String Handling - Exercises [Page 249]

APPEARS IN

Rupa Pandit Computer Applications [English] Class 10 ICSE
Chapter 10 String Handling
Exercises | Q 3. (i) (ii) | Page 249
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×