Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


bhaskarreddy
LOOPS !!
2 Answer(s)      5 years and 2 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

September 5, 2009 at 4:02 PM


String s="Hello";
System.out.println(s.length());
System.out.println(s.substring(0,1));
System.out.println(s.substring(0,2));
System.out.println(s.substring(0,3));
System.out.println(s.substring(0,4));
System.out.println(s.substring(0,5));


System.out.println(s.substring(4,5));
System.out.println(s.substring(3,5));
System.out.println(s.substring(2,5));
System.out.println(s.substring(1,5));
System.out.println(s.substring(0,5));


September 5, 2009 at 4:37 PM


Hi Friend,

Try the following code:

class StringPattern
{
public static void main(String[] args) {
String st="Hello";
for(int i=1;i<6;i++){
String sub1=st.substring(0,i);
System.out.println(" "+sub1);
}
st = new StringBuffer(st).reverse().toString();
for(int i=1;i<6;i++){
String sub1=st.substring(0,i);
System.out.println(" "+sub1);
}
}
}

Thanks


Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com