- 1
What mean this error message in Java? "Line 0 <identifier> expected" ? I need your help please!
Error message
14 Réponses
+ 3
In line 3 : you wrote
Public static toBinary (int num){
In this , 'p' must be small letter in public.
And return type is missing. you are returning 'binary' which is a string type so must specify return type as String.
So correct way to write is :
public static String toBinary (int num){
(You can upload to post section and share link here : for images)
Hope it helps.......
+ 2
Many thanks to you Jayakrishna🇮🇳 , i was declaring return type as string but the s was not in capital letter 🙈
I'm not yet used to java syntax and it's not correcting automatically the case sensitive issue...!
I'm happy to notice it, next time i will be careful!
+ 2
"All class names must start with a capital letter! " -: its not a rule .
( In your code , use converter in place of 'Converter' will works )
But it's a guide line for better readability.. Best to follow always..
Hope It helps ..
You're welcome..
+ 1
import java.util.Scanner;
public class Converter {
Public static toBinary (int num){
String binary="";
while(num > 0) {
binary = (num%2)+binary;
num /= 2;
}
return binary;
}
}
//your code goes here
public class Program {
public static void main(String[ ] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.print(Converter.toBinary(x));
}
}
+ 1
Jean BALEMBA
A variable in java are user defined so it's user choice like
int marks;
or
int Marks;
here , marks and Marks are both variables of int type but may have different values. not same. java is case sensitive language as you know it..
String is predefined class name in java.
int , double, char, ... are data types in java. And those are predefined keywords. So you can't change keywords and can't use them as variables. Must use as it defined in documentation..
+ 1
🙏Thank you for explaining it nicely, i didn't know that String was a predefined class name in Java.
All class names must start with a capital letter! 👌👍
+ 1
It helps alot! 🙏👍
0
Its a syntax error.
Showing code snippet may help to understand it more and to correct.. but for now it's less information atleast for me. Happy learning...
0
So how to post a picture here so i can send the screen shot of the java code?
0
Thanks alot Jayakrishna🇮🇳 , let me try it out!
0
How to specify the return type please?
0
Yes.
Capital S in String. Small p in public.
Return type must be specified before the method name in its definition.
You're welcome.....
0
By the way, when a variable type takes a capital letter in Java?
Why string must start by S but integer is int, or double or char...?