Write a program in Java To display pattern


Write a program in Java To display the given  pattern.

J

J A

J A V

J A V A

J A V A P

// Program To display the pattern

import java.io.*;

import java.util.*;

class jpattern

{

public static void main(String aa[])

{

Scanner sr=new Scanner(System.in);

int a,b;

String ss;

System.out.println(“Enter your word to print a pattern”);

ss=sr.next();

b=ss.length();

for(a=0;a<=b;a++)

{

System.out.println(ss.substring(0,a));

}

}

}

output :

jpattern

 

Related Posts

Comments are closed.