-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendUp
More file actions
23 lines (23 loc) · 846 Bytes
/
endUp
File metadata and controls
23 lines (23 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*Given a string, return a new string where the last 3 chars are now in upper case. If the string has less than 3 chars,
uppercase whatever is there. Note that str.toUpperCase() returns the uppercase version of a string.
endUp("Hello") → "HeLLO"
endUp("hi there") → "hi thERE"
endUp("hi") → "HI"
*/
public class endUp {
public static void main(String[] args) {
String output=endUp("Hello");
System.out.println(output);
String output1=endUp("hi there");
System.out.println(output1);
String output2=endUp("hi");
System.out.println(output2);
}
public static String endUp(String str){
if (str.length()>=3)
return str.substring(0,str.length()-3)+str.substring((str.length()-3)).toUpperCase();
else {
return str.toUpperCase();
}
}
}