0
How to separate elements of a string variable in java? added an extra question
Given a string, return true if it ends in "ly". endsLy("oddly") → true endsLy("y") → false endsLy("oddy") → false
5 Respuestas
+ 6
What language?
The general idea in C++ would be to get string size, copy string to char array, utilise info on string size to get the last two array index, evaluate the last two array if they correspond to ly.
If it's Ruby, you get to do negative array indexes which simplifies a lot of work.
+ 3
The method you want to use is called substring, it can be use to return the last two characters of your string and then you can test it in a condition.
Example: (Javascript)
var str1 = "oddly";
var str2 = str1.substr(-2);
if(str2=="ly"){
//do something
}else{
//do something
};
+ 2
String s;
s=in.readLine();
String s1;String s2="ly";
int l=length();
s1=s.substring(l-2,l);
if(s1.equalsIgnoreCase(s2))
//now write the statement
0
Java
0
thanks a lot. what does substring (); do?. actually i wanted to separate all the elements of a string and store it to a character array maybe. I'm a beginner, sorry i asked a simple question