AIM: Given a string, return a string made of the last 2 chars (if present),
however include last char only if it is 's' and include the second only if it is 'e', so
"includes" fields "es". endEs("Flies") → "es" endEs("Jars") → "s"
endEs("Bitter") → "e" in java
CODE:
import java.util.*;
public class Two{
static void endEs(String s){
if(s.endsWith("es")==true)
System.out.println("es");
else if(s.endsWith("s")==true)
System.out.println("s");
else if(s.length()>1) {
char c=s.charAt(s.length()-2);
if(Character.compare(c,'e')==0)
System.out.println("e");
}
}
public static void main(String args[])
{
char response='n';
Scanner in=new Scanner(System.in);
do{
System.out.println("Enter String: ");
String s=in.next();
endEs(s);
System.out.println("If You want to continue press (y) ,else press
(n)");
response=in.next().charAt(0);
}while(response=='y');
System.out.println("\nPrepared By: write your name here");
}
}
No comments: