| | |
Recognizing and working with an array's contents
![]() |
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
Use single quotes
a[k] = 'a';
This should work
Richard West
Use single quotes
a[k] = 'a';
This should work
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Solved Threads: 0
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;
}
}
}
}
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;
}
}
}
}
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
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
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
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
It does not work because of what you did above
This is the correct way
You have to use double equal signs. Change the rest as i listed in the above example
Yours Sincerely
Richard West
•
•
•
•
Originally Posted by MFal
if(a[k] = 'a')
This is the correct way
Java Syntax (Toggle Plain Text)
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
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
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
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
•
•
•
•
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)
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.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
•
•
•
•
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.
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: What is the Use of Apache Ant and CVS in the Java Development...?
- Next Thread: 'Unable to access jarfile'
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle physics plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree trolltech unlimited utility webservices windows






