-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDE_FRONT.java
More file actions
30 lines (26 loc) · 823 Bytes
/
DE_FRONT.java
File metadata and controls
30 lines (26 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
Given a string, return a version without the first 2 chars.
Except keep the first char if it is 'a' and keep the second char if it is 'b'.
The string may be any length. Harder than it looks.
deFront("Hello") → "llo"
deFront("java") → "va"
deFront("away") → "aay"
*/
package school;
public class DE_FRONT {
public static void main(String[] args){
String answer = deFront("Hello");
System.out.println(answer);
}
public static String deFront(String str) {
if(str.charAt(0)=='a' && str.charAt(1)!='b'){
return ("a" + str.substring(2,str.length()));
}else if(str.charAt(0)!='a' && str.charAt(1)=='b'){
return (str.substring(1,str.length()));
}else if(str.charAt(0)=='a' && str.charAt(1)=='b'){
return str;
}else{
return (str.substring(2, str.length()));
}
}
}