0

Whats wrong here?????

So, Im trying the caesar cipher challenge on java and i think that i code that i made(java) makes sense, my goal is that whatever letter you type it will be swapped with the next letter in the alfabet, but its only output are interrogation marks, plz someone help me out. https://code.sololearn.com/c36tWuvFpbBh/?ref=app

26th Jul 2019, 10:08 PM
Diogo H.
8 odpowiedzi
0
Thank you for the help, but I really wanted to understand why my code didn't worked, why it gave such a strange output.
27th Jul 2019, 2:15 AM
Diogo H.
0
I'm not sure what this code is about, but the problem is that the BufferedReader runs out of input characters and -1 is returned, which gives ? as a char. To avoid this, you must enter 48 characters times the length of the first line.
27th Jul 2019, 4:15 AM
Elmer Martens
Elmer Martens - avatar
0
What do you mean by enter 48 characters? Enter where?
27th Jul 2019, 4:27 AM
Diogo H.
0
Diogo H. I figured as much. I wouldn’t be able to type out all the problems I’m seeing, but as Elmer said, your issue with the question marks stems from line 37, “int x = br.read()” that is going to return the integer -1 which is the equivalent of a question mark character. I would suggest using encapsulation on your Caeaser method and passing the character you are trying to cipher into it
27th Jul 2019, 4:29 AM
Jake
Jake - avatar
0
Jake. But I'm not understanding why it is returning -1, i already tried "int x = br.read()" in another codes and it always returned the letter's corresponding number
27th Jul 2019, 4:48 AM
Diogo H.
0
Jake. Another thing, what another thing is wrong in my code? Not saying you are not right by saying that my code might have problems, i only have a couple weeks of programming, but i want to understand and learn more. Just give me an example of an error if you dont want to list all of then.
27th Jul 2019, 4:51 AM
Diogo H.
0
Diogo H. I cant say much about the buffered reader as anytime I’ve used it I’ve ran into a problem and decided to go a different route, so I dont know much about that... And well I’m not seeing a ton of problems, just some performance and structure stuff, but for one, your code is going to loop at the very least 50 times and print 50 characters (more so if you enter more than 1 letter) because your while loop condition in the main method is <= test.length() and your while loop condition in the caeser method is <=24 with no breakouts meaning it will loop at least 2x25
27th Jul 2019, 5:27 AM
Jake
Jake - avatar
0
Jake. Ok, thanks for the help👍👍
27th Jul 2019, 3:04 PM
Diogo H.