How exactly do you use charAt in java. I understand some of the basics but how do I allow for it to read each character.
help with javacharAt
Page 1 of 1
7 Replies - 6549 Views - Last Post: 05 May 2005 - 11:49 AM
Replies To: help with java
#2
Re: help with java
Posted 05 May 2005 - 11:28 AM
Your 'String' is an array of characters.
It's (kind of) like char word[]; in a sense.
for example:
String name = new String("Bob");
understand? Then:
name.charAt(0) = 'B';
is true and:
name.charAt(2) = 'b';
and finally:
name.charAt(1) = 'o';
so to read characters, say it as an array. Use a for or while loop.
To look one step ahead of the array, say it like this when num is zero:
name.charAt(num+1) = 'o';
Does that help you?
It's (kind of) like char word[]; in a sense.
for example:
String name = new String("Bob");
understand? Then:
name.charAt(0) = 'B';
is true and:
name.charAt(2) = 'b';
and finally:
name.charAt(1) = 'o';
so to read characters, say it as an array. Use a for or while loop.
To look one step ahead of the array, say it like this when num is zero:
name.charAt(num+1) = 'o';
Does that help you?
#4
Re: help with java
Posted 05 May 2005 - 11:30 AM
I know that helped you.
I am more helpful over the computer than in person.
I am more helpful over the computer than in person.
#5
Re: help with java
Posted 05 May 2005 - 11:42 AM
so will this work?
char test = new char[50];
String input;
input = Keyboard.readString();
for(int i = 0; i < input.length(); i++)
{
blah[i] = input.charAt(i);
}
char test = new char[50];
String input;
input = Keyboard.readString();
for(int i = 0; i < input.length(); i++)
{
blah[i] = input.charAt(i);
}
#6
Re: help with java
Posted 05 May 2005 - 11:44 AM
Sounds like a good idea.
Try it out, I see no reason why it shouldn't work.
Try it out, I see no reason why it shouldn't work.
#7
Re: help with java
Posted 05 May 2005 - 11:48 AM
ok cool that worked out....thanks for the help =)
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|