aspose file tools*
The moose likes Beginning Java and the fly likes what identifier?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what identifier??" Watch "what identifier??" New topic
Author

what identifier??

Sarah Adam
Greenhorn

Joined: Oct 14, 2003
Posts: 5
I'm using JBuilder Professional 6 for my programming projects.
Well, I've written some codes and JBuilder keeps saying that an identifier is expected in the following line: static int characterToCode(char 'a'){
============(this is part of the programme, where it takes the char input from the user and converts it into a number/integer)
//char to code conversion
static int characterToCode(char 'a') {
int b = (int)a;
return b;
System.out.println("The code value for '"+ a +"' is "+ b +".");
myCharacterList[i] = a;
myCodeList[i] = b;
i ++;
}
===============
If someone could help me ASAP, i'd be realllly grateful. Thank you in advance!
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

It's the enclosing single quotes in the parameter variable a that is confusing the compiler. Remove those and try again.


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Sarah Adam
Greenhorn

Joined: Oct 14, 2003
Posts: 5
Yes, I have tried your suggestion but that doesnt seem to be the problem. Because: 1)It generated even more error 2)For char variables, it is a must to have the single quotation marks.
Hence the problem still hasnt been solved...
Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
hiiiii
i agree with Michael Ernest .. if characterToCode() is a method then there should not be single quotes as "a" is variable name and not a value.
the errors seems to be in other place... like when u r calling the method characterToCode() then how r u passign the parameter.. are u passing that character in double quotes or single quotes.. it should be passed in siingle quotes.. and another error that might be coming which u have not mentioned is that u r writing return before lot of statement.. which whould be resulting in error as "Unreachable statement..."
it would be better if you paste more code and also the excat error message... then we might be able to help more..
thanks
Amit


****************************<br />In 24 hrs Earth rotates once on its Axis.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Hey Sarah -
Well that's because you have more than one problem in the code, starting with that 'a' thing. I was going to tackle these one at a time, but let's go through it:
1) In order to express a literal character, you do need to enclose one in single quotes. This rule does not apply to parameters. In your method name, you are declaring a character parameter a, not a literal 'a'.
2) Your return statement has to be the last statement in the method body. Any code after the return statement is dead code and won't execute.
3) I assume the variable i and the arrays myCharacterList and myCodeList are declared outside the method. Also the array size must be instantiation before they can be used.
4) There may be more problems depending on 3).
Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
yeah..
there can be more errors like
those arrays and variable need to be static as they are being called from a static method...
Thanks
Amit
Narayan Nayak
Greenhorn

Joined: Sep 20, 2002
Posts: 6
remove single quote
class Test
{
static int characterToCode(char a) {
int b = (int)a;
System.out.println("The code value for '"+ a +"' is "+ b +".");
return b;
}

public static void main(String[] args)
{
int i=Test.characterToCode('c');
System.out.println("Hello World!"+i);
}
}
test this


Narayan
Sarah Adam
Greenhorn

Joined: Oct 14, 2003
Posts: 5
to Narayan: I've tried that. It works very well . May I know what Test.characterToCode(char a) does?
to others: Ok, I've removed the single quotes and corrected the other careless mistakes like leaving out them semicolons ( . I've also made corrections for my return statements to be the last statement of their respective methods.
Now, JBuilder says that my errors are as follows:
static void endMethod() {
if ((myCodeList.length-1 >= 0) || (myCharacterList.length -1 >= 0)){
System.out.println("Character" + "\t\t\tCode");
System.out.println(myCharacterList[] + "\t\t\t"+ myCodeList[]);
}
else
System.out.println("Thank you for using the programme!");
JBuilder: illegal start of expression at line 71. illegal start of type at line 71.
Line 71 is the line which I have bolded for you.
So what's so illegal?
Before that, I shall explain what I'm trying to do.. lol. I'm trying to say that if the array is not empty, then the records/arrays will be printed. If the array is empty, the records/arrays wont be printed and the programme would just exit out of the whole programme.
In the main method, I've done this (the following) to call the endMethod and thereafter exit the programme.
endMethod();
System.exit(0);
Thank you for your prompt replies so far! : )
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Well, I don't see anything wrong with the line of code you've highlighted, in fact it compiles fine for me, but the following line is definitely flawed.
To refer to your array objects, just use the variable names, don't use the variable names plus those brackets. The name of the myCharacterList array is myCharacterList not myCharacterList[].
[ October 16, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
[And a small tip...]
The typical idiom to determine whether an array has at least one element in it is if (array.length > 0)
When I see it expressed this way, I quickly know the meaning of the boolean test. I had to stop and think for a second to realize that you were trying to express the same thing with if (array.length - 1 >= 0)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what identifier??