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

24th Nov 2017, 2:09 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
15 Antworten
+ 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.
24th Nov 2017, 3:15 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Your code won't work of if you don't follow my mention
24th Nov 2017, 3:40 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Update your code
24th Nov 2017, 5:37 PM
Jonas Schröter
Jonas Schröter - avatar
+ 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!
24th Nov 2017, 7:01 PM
Jonas Schröter
Jonas Schröter - avatar
+ 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.
24th Nov 2017, 7:35 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
So, in your for loop there's <=, use only < and you're good to go.
24th Nov 2017, 8:16 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
Haha😊
24th Nov 2017, 8:25 PM
Jonas Schröter
Jonas Schröter - avatar
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
24th Nov 2017, 3:26 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
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.
24th Nov 2017, 3:34 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
0
Whats next? i took your feedback.
24th Nov 2017, 3:55 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
0
sorry , guess i didnt save it when i updated it the first time. I did it again.
24th Nov 2017, 5:42 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
0
Thank you , i appreciate the help
24th Nov 2017, 7:18 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
0
Quick question, does this code only apply if the character is a letter(any letter)? does it not apply to a specific letter?
24th Nov 2017, 7:22 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
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.
24th Nov 2017, 8:11 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
0
I swear my eyes play games on me when im coding. Thank you!
24th Nov 2017, 8:20 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar