A Type of Loop
Hey guys,
I was wondering if anyone could help me. I need to create a small java class that takes a string input from the user (i know how to do that) and output that same string, but formatted as such:
IE: User enters the word 'Purple'
It is output on the screen like this: 'P:Pu:Pur:Purp:Purpl:Purple'
If anybody could give me any pointers that would be great
Thanks
h
[417 byte] By [
madHattera] at [2007-11-26 17:42:01]

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
Describe the steps in English or pseudocode first. Imagine you're explaining to somebody who can only understand very simple, precise instructions, but will do exactly what you tell him. He won't understand examples.
Your do-my-homework-for-me request has been entered into the system. Please stand by.
> Your do-my-homework-for-me request has been entered> into the system. Please stand by.Well he did ask for "pointers", not "teh codez", and he did type in legible English. Hopefully he'll follow the link provided.
> > Your do-my-homework-for-me request has been
> entered
> > into the system. Please stand by.
>
> Well he did ask for "pointers", not "teh codez"
I think it's just a matter of time. It's coming, just wait and see. (Or he'll just vanish)
Edit: Ok, he replied after this proving me wrong (maybe). But I still believe he's basically going to go nowhere until someone codez it up for him. I just betcha.
I dont want somebody to give me all the answers, Just a few hints in the right direction would be appreciated :)
> I dont want somebody to give me all the answers, > > Just a few hints in the right direction would be> appreciated :)You got two very good ones.
> I dont want somebody to give me all the answers,
>
> Just a few hints in the right direction would be
> appreciated :)
The best way to get that is to post the code that you have, demonstrating what you've tried. That way we can go "Oh, you need to do this," or "You did this wrong, try this." Show us what you have so far.
> I dont want somebody to give me all the answers,
>
> Just a few hints in the right direction would be
> appreciated :)
@OP: Yes, the hints provided were good hints for what you want to do. Also, you might want to check out: http://java.sun.com/docs/books/tutorial/java/data/strings.html
Message was edited by:
Djaunl
i followed the link from DrLaszloJamfamd looking through that now, hopefully ill solve my problem soon :)thanks
One little hint: look at the substring() method of the String class.
Got it
String input;
Scanner stringScanner = new Scanner(System.in);
System.out.println("Enter a String :");
input = stringScanner.nextLine();
int length = input.length();
for(int i=1; i<=length; i++)
{
System.out.print(input.substring(0,i) + ":");
}
works ok for me:)
I hope it didn't really take 2 weeks to come up with that.