Reputation: 7
How to print a string like below?
S
St
Str
Stri
String
I have tried this, but I don't know how to proceed after this:
String s = "string";
for (int i = 1; i <= s.length(); i++)
{
System.out.println(s.charAt(i));
}
Upvotes: 0
Views: 86
Reputation: 972
using substring?
String s="stringyyyyiyi";
for(int i=1;i<=s.length();i++)
{
System.out.println(s.substring(0,i));
}
Upvotes: 2