6th Aug 2017, 4:59 PM
Mayur Chaudhari
Mayur Chaudhari - avatar
4 Réponses
+ 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
8th Aug 2017, 5:20 AM
visph
visph - avatar
+ 2
What am I supposed to input?
6th Aug 2017, 5:46 PM
Jonas Schröter
Jonas Schröter - avatar
+ 1
thanks bro it's really helpful to me
8th Aug 2017, 5:25 AM
Mayur Chaudhari
Mayur Chaudhari - avatar
0
now click on that code everything is provide in code
8th Aug 2017, 4:11 AM
Mayur Chaudhari
Mayur Chaudhari - avatar