- 1

What mean this error message in Java? "Line 0 <identifier> expected" ? I need your help please!

Error message

4th Oct 2021, 6:36 PM
Jean BALEMBA
14 Answers
+ 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.......
4th Oct 2021, 7:07 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 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!
4th Oct 2021, 7:40 PM
Jean BALEMBA
+ 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..
4th Oct 2021, 8:15 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 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)); } }
4th Oct 2021, 6:53 PM
Jean BALEMBA
+ 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..
4th Oct 2021, 7:55 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
+ 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! ๐Ÿ‘Œ๐Ÿ‘
4th Oct 2021, 8:00 PM
Jean BALEMBA
+ 1
It helps alot! ๐Ÿ™๐Ÿ‘
4th Oct 2021, 8:55 PM
Jean BALEMBA
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...
4th Oct 2021, 6:41 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
0
So how to post a picture here so i can send the screen shot of the java code?
4th Oct 2021, 6:49 PM
Jean BALEMBA
0
Thanks alot Jayakrishna๐Ÿ‡ฎ๐Ÿ‡ณ , let me try it out!
4th Oct 2021, 7:10 PM
Jean BALEMBA
0
How to specify the return type please?
4th Oct 2021, 7:14 PM
Jean BALEMBA
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.....
4th Oct 2021, 7:44 PM
Jayakrishna ๐Ÿ‡ฎ๐Ÿ‡ณ
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...?
4th Oct 2021, 7:49 PM
Jean BALEMBA