HomeForumsWhat's newResources 
 
 
Anyone good with java?
Scared0o0Rabbit - Apr 20, 2004
 Scared0o0Rabbit Apr 20, 2004
Didn't see a general dev, or pc dev section, so here's the question...

How do I get individual characters out of a string one at time? My compsci teacher is useless, and this is due tonight before midnight.

 Zziggy00 Apr 20, 2004
Stringname.charAt(int location)

ex.

say you wanted to print each character in the String "Book"

String blah = "Book";

char blah2 = '';

for (int x=0;x
{

blah2 = blah.charAt(x);

System.out.println(blah2);

}

This would output:

B

o

o

k

and for your second problem use the same kinda thing, just have an IF statement so that if it finds the sentinal value (i'm guess your end of line thing) it breaks out of the loop....

for (int x=0;x
{

blah2 = blah.charAt(x);



if (blah2.equals('k') == true)

{

break;

}

System.out.println(blah2);



}

This should output:

B

o

o

Someone want to test this for me, or correct me if im wrong?

 MasterAkumaMatata Apr 20, 2004
http://java.sun.com/j2se/1.4.2/docs/api/ja...ang/S...

Code:
  
String Akuma="The Aging Demon";

for (int index=0; index < Akuma.length(); index++){

  System.out.print(Akuma.charAt(index));

}

My java is a bit rusty, is that what you're looking for?

 Scared0o0Rabbit Apr 20, 2004
thanks

 IceDigger Jun 23, 2004
Scared0o0Rabbit, the wolf in your sig looks almost exactly like my new dogga.

 racketboy Jun 23, 2004
I haven't seen Scared in a while