How to make a Triangle pattern of words using Given String

How to make a Triangle pattern of words using Given String
SOURCE : StringTriangleWords.java

import java.util.StringTokenizer;

public class StringTriangleWords {
public static void main(String[] args) {

String s1 = "this is the country which is my first love ";

StringBuffer sb = new StringBuffer();
StringTokenizer st = new StringTokenizer(s1);

while (st.hasMoreTokens()) {

System.out.println(sb.append(st.nextToken() + " "));
}
}

}



INPUT

String s1 = "this is the country which is my first love "



OUTPUT

this
this is
this is the
this is the country
this is the country which
this is the country which is
this is the country which is my
this is the country which is my first
this is the country which is my first love






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment