+ 2
Can enyone help me a bit with a code problem?
I have written a programm and debuged it as well as possible, but every time I run it, it throws an exception. Here is the code : https://code.sololearn.com/c3SW5DMSm39a/?ref=app
8 Réponses
+ 3
Can you explain what your code should do?
What should I input and what is the expected output?
E.g. if I input "hello world" what is the output?
I need my IDE on my laptop to have a closer look on your code. Maybe I can find the problem tomorrow (here it is 23:45 and I have to sleep ;)).
+ 3
Giorgos
I have found a problem. You have the arrays casentence2 and casentence. The length of theese arrays depends on your input.
But in your switch statement:
casentence2[1 + l] = casentence[5 + l];
If length of input < 6 --> error
You should use the real index.
You know the length of the array. So you can calc the needed index.
Last index is length - 1; second last: length - 2...
+ 3
More stuff:
* import java.io is never used
* value of variable d (double d = 0.0) is not used
* eclipse shows also a message about your char seven -> value of seven is not used
e.g. char seven = casentence2[7 + l] -> why do you need this char?
* l -> you start with 0 and after case 'D' -> l += 8 -> also a problem. I tested a word with length 15: casentence2[4 + l] = casentence[7 + l]
l was 8, 4 + 8 = 12 but 7 + 8 = 15
-> out of index
I think you should write a new code.
Make a plan what you want to do, use comments, use more methods. If you have a method for each small task, it is easier to debug. Test each method while coding. (Write method -> test it -> write next method)
+ 2
Line 58:
char[] scramble = Scramble.creatScramble(i);
i is a random number between 1-10. But you don't use i in your createScramble method. Why is i a parameter of this method?
+ 1
This code is too large and confusing, it's hard to debug and you don't have comments in it. It throws an ArrayOutOfBoundsException when you are accesing casentence2[n + l] in lines above 400 you should check that your array isn't too short before accessing the values.
+ 1
As I said in your previous thread, I think you should figure out a better implementation of that algorithm. Can you give me the basic algorithm idea? I will try to code it
0
It reorganizes the letters... The output of sololearn with a scramble(the method used to reorganize the letters) U, would be lsoreloan