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]
# 1
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/for.html
DrLaszloJamfa at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 2
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.
jverda at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 3
Your do-my-homework-for-me request has been entered into the system. Please stand by.
warnerjaa at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 4
> 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.
Djaunla at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 5

> > 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.

warnerjaa at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 6
I dont want somebody to give me all the answers, Just a few hints in the right direction would be appreciated :)
madHattera at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 7
> 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.
jverda at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 8

> 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.

hunter9000a at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 9

> 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

Djaunla at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 10
i followed the link from DrLaszloJamfamd looking through that now, hopefully ill solve my problem soon :)thanks
madHattera at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 11
One little hint: look at the substring() method of the String class.
bckrispia at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 12

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:)

madHattera at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...
# 13
I hope it didn't really take 2 weeks to come up with that.
warnerjaa at 2007-7-9 0:10:12 > top of Java-index,Java Essentials,New To Java...