+ 3
Code
what is wrong in my code?? https://code.sololearn.com/cqws0lEsf2ZK/?ref=app
4 odpowiedzi
+ 4
> First, you declare your 'str' char array in a bad way:
char[] str[];
... should be:
char str[];
... or even:
char[] str;
... else, you're trying to declare an 2d array (str[][])
> Second, you forgot to initialize your 'str' array before accessing it in the two last loops (copy and output):
str = new char[string.length];
> Next, you need to initialize 'f' and 't' variables, else assignements in first loop seems to no work (and throwing error)
int f = -1,t = -1,i,j,k;
... set them to -1, to explicitly have a 'non-initialized' value
> At this point, the code is almost working, but with some bug cases, starting by your example (welcome, e, m) which will output nothing because the last 'e' position is saved as 'f', which comes after (f>t) the found 'm'... So, you need to improve you first loop ^^ (in which last else statement is unecessary ;P)
> Also, when you 'println' each char of result, you make a break line after each... maybe you can use 'print' and only at end do a 'println' (for outputing a line break -- if you have other outputs after)
Fixed and improved code, with some log added:
https://code.sololearn.com/cpHBbmjUnLuU/?ref=app
+ 2
What am I supposed to input?
+ 1
thanks bro it's really helpful to me
0
now click on that code everything is provide in code