• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make this loop?  RSS feed

 
Jon Peterson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make a loop that starts with "abcdefghijklmnopqrstuvwxyz" . and every time it loops it drops one letter. Thus ending in "z" . I'm sure this is very simple, but I am very new. :P Any help?
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This may help you on your way:


static void sjekk(String s) {
for(int i=0;i<s.length();i++) {
System.out.println(s.substring(i)); // substring is your friend
}
}
public static void main(String[] args){
String s="abcdefghijklmnopqrstuvwzyz"; //for testing
sjekk(s);
}
 
Jon Peterson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha! Gotcha, thanks! I got turned around when someone told me to use 'Char.' Turned me around pretty bad. :P
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T Dahl,
it would have been so much fun if you had given hints instead of code, wouldn't it ? And next time you post some code, please UseCodeTags
 
Jon Peterson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it was kind of a hint... I used a few variations and adapted it to my own style, but it was good for a base outline.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
T Dahl
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:T Dahl,
it would have been so much fun if you had given hints instead of code, wouldn't it ? And next time you post some code, please UseCodeTags

yes, I agree. I will try to be more pedagogical from now on.

I was disapointed by the appearance of my code, but figured out the code tag thing for my next post. Looked much nicer that way.

I am new to the forum and have to learn its culture and techniques. Looks like a nice place.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
T Dahl wrote:I am new to the forum and have to learn its culture and techniques. Looks like a nice place.

It is a nice place. Welcome here !
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!