0
Help with my code pls
https://code.sololearn.com/cqm4PwX0u8Yv/#java Thats the link to the code. Im trying to make a encrypt-er. Where you type in a word and its prints a number in replace of each letter but i have a problem; it states char cannot be deferred
15 Respostas
+ 1
So there a many errors in your code. First check if you have set your curly brackets properly.
If you create a variable, it's name musn't be the same as a class already existing, if you write this, your program won't compile:
String String = "Wrong"
This is correct:
String string = "Correct"
And in Sololearn Playground you don't want to type the package name at the top, you don't need this here, the compiler does not find you main class.
Fix those issues, then you can go on fixing your code.
+ 1
Your code won't work of if you don't follow my mention
+ 1
Update your code
+ 1
Next, you have to import the Scanner class.
After this, there's a problem:
"char cannot be dereferenced"
That's because the isLetter() method is static, so you call it like this:
Character.isLetter (char c);
Now your code compiles!
+ 1
So, the method isLetter() checks if the Character is a letter.
For a specific letter you could use switch(alpha),
but this would be much work.
You could also use Integer.valueOf (alpha) to get the ascii number, which you can print, or add for example 1 to it to ecrypt your input.
+ 1
So, in your for loop there's <=, use only < and you're good to go.
+ 1
Hahađ
0
i just copied my code from netbeans lol. Im not trying to run it in the sololearn compiler.Also the variable naming element, i originally had in the correct format but it still gave me the same error. Thanks anyway
0
when you mentioned the variable naming convention were you referring to the variable "Letter"? if so i get your point but it doesnt really affect the functionality of the code hey, unless theres something im missing.
0
Whats next? i took your feedback.
0
sorry , guess i didnt save it when i updated it the first time. I did it again.
0
Thank you , i appreciate the help
0
Quick question, does this code only apply if the character is a letter(any letter)? does it not apply to a specific letter?
0
I'll definitely research that , thank you. Could you possibly look at my code again, i managed to do it in my own way , hence im getting the correct output but at the same time i have an error. If you test my code out by typing in a sentence or word, you will get the corresponding values in order.
0
I swear my eyes play games on me when im coding. Thank you!