944,031 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2109
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 30th, 2005
0

Recognizing and working with an array's contents

Expand Post »
In my code i take an inputted number, which could be in hex with letters, and put each individual digit into a seperate space in an array. To change the letters in hex to numbers in decimal, i tried doing it two ways: (a is my array name, and i am trying to check to see if the character at k in my array is the letter a.)

if (a[k] = "a")
which gives me an "incompatible types" error
or
if (a.charAt[k] = "a")
which gives me a "cannot resolve symbol method charAt(int)"


I don't have any idea what to do from here, or even if i'm remotely close to being right. Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MFal is offline Offline
5 posts
since Jul 2005
Jul 30th, 2005
0

Re: Recognizing and working with an array's contents

Hi everyone,

Use single quotes

a[k] = 'a';

This should work

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jul 30th, 2005
0

Re: Recognizing and working with an array's contents

Thanks a lot for responding.

I just tried that after i read your post, but it is still giving me an "incompatible types" error for the else if statements, oddly enough not the original if statement though.

else if(base == 11 || base == 12 || base == 13 || base == 14 || base == 15 || base == 16)
{
int j;
int i;
int k;

for (i = 0; i < Num.length(); i++)
{
a[i] = Num.charAt(i);
}

for (k = 0; k < a.length; k++)
{

if(a[k] = 'a')
{
a[k] = 1;

for (k = k + 1; k < a.length; k++)
{
a[k] = a[k + 1];
a[k] = 0;
}
}

else if(a[k] = 'b')
{
a[k] = 1;

for (k = k + 1; k < a.length; k++)
{
a[k] = a[k + 1];
a[k] = 1;
}
}

else if(a[k] = 'c')
{
a[k] = 1;

for (k = k + 1; k < a.length; k++)
{
a[k] = a[k + 1];
a[k] = 2;
}
}

else if(a[k] = 'd')
{
a[k] = 13;

for (k = k + 1; k < a.length; k++)
{
a[k] = a[k + 1];
a[k] = 3;
}
}

else if(a[k] = 'e')
{
a[k] = 14;

for (k = k + 1; k < a.length; k++)
{
a[k] = a[k + 1];
a[k] = 4;
}
}

else if(a[k] = 'f')
{
a[k] = 15;

for (k = k + 1; k < a.length; k++)
{
a[k] = a[k + 1];
a[k] = 5;
}
}
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MFal is offline Offline
5 posts
since Jul 2005
Jul 30th, 2005
0

Re: Recognizing and working with an array's contents

Quote originally posted by MFal ...

for (i = 0; i < Num.length(); i++)
{
a[i] = Num.charAt(i);
}

You're grabbing numbers, so try parsing to a char:

a[i] = (char)(Num.charAt(i));

or try this:

a[i] = (Num.charAt(i)).charValue();
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jul 31st, 2005
0

Re: Recognizing and working with an array's contents

Hi everyone,

server_crash is it my browser or is it everyone's post seems to be cut of at the end. Please let me know so maybe i can let dani about it

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jul 31st, 2005
0

Re: Recognizing and working with an array's contents

Hi everyone,

Quote originally posted by MFal ...
if(a[k] = 'a')
It does not work because of what you did above

This is the correct way

Java Syntax (Toggle Plain Text)
  1. if(a[k] == 'a')

You have to use double equal signs. Change the rest as i listed in the above example

Yours Sincerely

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jul 31st, 2005
0

Re: Recognizing and working with an array's contents

Quote originally posted by freesoft_2000 ...
Hi everyone,

server_crash is it my browser or is it everyone's post seems to be cut of at the end. Please let me know so maybe i can let dani about it

Richard West
Not any changes here. If your missing something or can't see something, let me know what exactly it is, so I can let you know if it's missing on my part too. But everything seems normal here.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jul 31st, 2005
0

Re: Recognizing and working with an array's contents

Quote originally posted by freesoft_2000 ...
Hi everyone,



It does not work because of what you did above

This is the correct way

Java Syntax (Toggle Plain Text)
  1. if(a[k] == 'a')

You have to use double equal signs. Change the rest as i listed in the above example

Yours Sincerely

Richard West

:eek: I would have never caught that. One of the hardest mistakes to spot.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jul 31st, 2005
0

Re: Recognizing and working with an array's contents

Quote originally posted by server_crash ...
Not any changes here. If your missing something or can't see something, let me know what exactly it is, so I can let you know if it's missing on my part too. But everything seems normal here.
I seem to be missing the last line. My name always gets cut off like this reply. Are having this problem as well??

Richard West
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Jul 31st, 2005
0

Re: Recognizing and working with an array's contents

Nope. I always see your name and your beginning salutation. Altought, I didn't see the salutation this time...But I think you just forgot it. Your name is there though.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: What is the Use of Apache Ant and CVS in the Java Development...?
Next Thread in Java Forum Timeline: 'Unable to access jarfile'





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC