+ 2
whats the problem?
this code is an encryption code. i tried to do the encryption using methods and i have an error that i dont know how to fix. code: https://code.sololearn.com/cMMXY723qqoW whats the problem? how to fix it?
9 Réponses
+ 2
i doesn't exist in the decrypt() method. You're not saving the encrypted text at all. Just outputting each char. Try saving the encrypted text and returning it from the call to e.encrypt() then pass the encrypted text to the decrypt method. e.decrypt(txt)
+ 2
BTW, don't ever use this type of "encryption" for an actual program. It's fine for practicing and learning, but if this where used to say encrypt actual passwords etc, it would be far too easy to crack.
https://code.sololearn.com/c2AQOv5V13GI/?ref=app
+ 2
yahel here's a way just reusing the sentence variable of the class.
https://code.sololearn.com/cOM2ka68pOZn/?ref=app
+ 2
You don't need it in those locations. I was being explicit for clarity. I've removed it so you can see that the code works the same. 'this' just refers to the current instance of the object.
+ 1
Thanks!
0
i am trying and i cant find a valid way to make it work? can you show me how you do it?
0
Ok, is there an other way that I just store a variable outside the method and then just assigning the encrypted sentence to it?
0
public static void main(String[] args) {
...
e.encryped();
System.out.println();
e.setSentence("nkrru2&s&tgsk&oy&gnkr''");
e.decryped();
public void decryped(){
for (char d : sentence.toCharArray() ){
0
Why do you need the 'this' keyword in line 39 btw?