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.

Recommended Answers

All 13 Replies

Hi everyone,

Use single quotes

a[k] = 'a';

This should work

Richard West

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 = 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;
}
}
}
}
      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();

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

Hi everyone,

if(a[k] = 'a')

It does not work because of what you did above

This is the correct way

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

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.

Hi everyone,

It does not work because of what you did above

This is the correct way

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.

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

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.

Hi everyone,

I didn't see the salutation

You can't see the name Richard West at the end right?

If you click on this thread's quote you will see that its there but on this post it does not appear. Do have that same problem too??

Richard West

No no, I can see your name and everything. But in one of your posts this was missing:

"Hi everyone".. I know you always put it there, so I'm guessing it's just a mistake. I can see your name and stuff at the bottom. If you like, I can take a screenshot of what I have.

Hi everyone,

I didn't miss it but let me see the screenshot. it seems this only happens if i use quote tags

Richard West

Here's a few pictures with quotes. None of yours is missing anything except one, and I got a pic of that one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.