-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterToggler.java
More file actions
30 lines (28 loc) · 996 Bytes
/
Copy pathCharacterToggler.java
File metadata and controls
30 lines (28 loc) · 996 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
// Write a program to input a string and print out the text with the uppercase
// and lowercase letters reversed, but all other characters should remain the
// same as before.
// Example:
// INPUT : WelComE TO School
// OUTPUT : wELcOMe to SCHOOL [15]
import java.util.*;
class CharacterToggler {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter any string :");
String s = sc.nextLine();
int len = s.length();
String s1 = "";// second string
for (int i = 0; i < len; i++) {
char ch = s.charAt(i);
if (Character.isUpperCase(ch)) {
s1 = s1 + Character.toLowerCase(ch);
} else if (Character.isLowerCase(s.charAt(i))) {
s1 = s1 + Character.toUpperCase(ch);
} else {
s1 = s1 + s.charAt(i);
}
}
s = s1;
System.out.println(s);
}
}