Anyone good with java?

Scared0o0Rabbit

Established Member
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.
 
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<blah.length();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<blah.length();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?
 
Back
Top