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 [पृष्ठ २४९]
