Write a program to display the given pattern for string input.
Sample input: INDIAN
Sample Output:
INDIAN
INDIA
IND
IN
D
Answers
#input
word = 'TAMILAN'
print (word)
print ( word [0 : 5] )
print ( word [0 : 4] )
print ( word [0 : 3] )
print ( word [0 : 2] )
print ( word [0 : 1] )
print ( word [0] )
#output
TAMILAN
TAMILA
TAMIL
TAMI
TAM
TA
this is done by using python programming.
and the numbers are 'ariyals’ which indicates the place of the word. ex. T is 0 and A is 1 as Same as N =6.
T
CORRECTED QUESTION:
Write a program to display the given pattern for string input.
Sample input: INDIAN
Sample Output:
INDIAN
INDIA
IND
IN
N
REQUIRED PROGRAM:
Refer the attachment ✔️
Or
/ Pattern1.java */
import java.util.*;
public class Pattern1
{
public static void main (String args [ ])
{
Scanner scan = new Scanner (System.in);
int length;
System.out.println ("Enter a word:");
String word = scan.next ();
length = word.length ();
for (int i = 0; i<= length; i++)
{
for (int j = 0; j < 1; j++)
{
System.out.println(" ");
}
System.out.println(word.subsyring(0, length-i));
}
scan.close( );
}
}
Walkthrough:
Line22: From 0 th position it is displaying substring until (length-i) th position.
Line 18: It is displaying spaces until value of loop control variable i.
Line 19: It is displaying spaces until value of loop control variable i.
Line 20: It is displaying spaces until value of loop control variable i.
Line 21: It is displaying spaces until value of loop control variable i.
Output:
Enter a word: INDIAN
INDIAN
INDIA
INDI
IND
IN
N