हिंदी

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

प्रश्न

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

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 10: String Handling - Exercises [पृष्ठ २४९]

APPEARS IN

रुपा पंडित Computer Applications [English] Class 10 ICSE
अध्याय 10 String Handling
Exercises | Q 3. (i) (ii) | पृष्ठ २४९
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×