-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendUp.java
More file actions
32 lines (31 loc) · 1.06 KB
/
Copy pathendUp.java
File metadata and controls
32 lines (31 loc) · 1.06 KB
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
31
32
/*
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.
*/
package codingbat;
import java.util.*;
public class endUp {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
char alph;
System.out.print("Enter a string: ");
str = sc.nextLine();
if(str.length() <= 3){
str = str.toUpperCase();
}
else{
String revstr = new StringBuilder(str).reverse().toString();
StringBuilder temp = new StringBuilder(revstr);
for(int i = 0; i < 3 ;i++){
alph = Character.toUpperCase(revstr.charAt(i));
temp.setCharAt(i, alph);
}
String orgstr = new StringBuilder(temp).reverse().toString();
str = orgstr;
}
System.out.print("Result: "+str+"\n");
}
}