+ 3
Code Coach solution issue - Java
https://code.sololearn.com/cW0kVfvYmrYw If you give two inputs either https://youtu.be/CwROcBKXsus (short youtube link) or https://www.youtube.com/watch?v=CwROcBKXsus a longer youtube link we are expected to get the output CwROcBKXsus however in my case I am not! This is a method quite based on compromise rather than a true solution to the problem so i would be grateful if someone could provide other ways of solving this as well.
6 Answers
+ 5
Thanks everyone for your answers it helped a lot.
+ 7
Ojas Kanotra ,
ChaoticDawg , has given you a hint how this task can be done in a simple way.
to make it a bit more clear:
âŞď¸after taken the input with scanner and storing it in a string variable, you can get the length of the input string by using the string method .length()
âŞď¸take the length and subtract 11 (the length of the relevant part of the link) and store this value in an integer variable
âŞď¸use substring method with the input string and with the int argument from last step. this will give you the final link for output
....
Scanner read = new Scanner(System.in);
String link = read.nextLine();
int startPos = link.length() - 11;
System.out.println(link.substring(startPos));
....
+ 4
You may or may not have noticed that the info that you need is always the last 11 characters of the input. This means that you can simply solve this by getting that portion (substring) of the input. This means you don't need to look for the difference between the 2 styles of input and can either just get the substring using the last index of the input for 'end' and the 11th index from the 'end' as the 'start' for your substring. You could also just loop through the last 11 characters if you prefer to use a loop.
+ 4
Ojas Kanotra I did it the hard way too đ I reversed the string (which I also did the hard way) and then used indexOf to find the = or / (which told me the format) and then used the return value to extract the substring. I didnât realize it would always be 11 characters 𤣠My code was twice as long as yours đ˛
+ 3
At this lines:
if (x.charAt(13) == c) {
The c must be 'c'
Same in the other case.
Your loops have to stop at
y < x.lenght() not at
y <= x.lenght()
Because:
The index of chars in the string is zero based. First char is at pos. (0).
The last one
is at pos. (lenght - 1)
+ 2
Its showing string index out of bound exception i think their is mistake is in your loop check it properly