-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathToggle_String.java
More file actions
58 lines (53 loc) · 1.37 KB
/
Toggle_String.java
File metadata and controls
58 lines (53 loc) · 1.37 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.*;
import java.lang.*;
/*
You have been given a String
S
S consisting of uppercase and lowercase English alphabets. You need to change the case of each alphabet in this String. That is, all the uppercase letters should be converted to lowercase and all the lowercase letters should be converted to uppercase. You need to then print the resultant String to output.
Input Format
The first and only line of input contains the String
S
S
Output Format
Print the resultant String on a single line.
Constraints
1
≤
|
S
|
≤
100
1≤|S|≤100 where
|
S
|
|S| denotes the length of string
S
S.
SAMPLE INPUT
abcdE
SAMPLE OUTPUT
ABCDe
URL: https://www.hackerearth.com/practice/basic-programming/input-output/basics-of-input-output/practice-problems/algorithm/modify-the-string/
*/
class TestClass {
public static void main(String args[] ) throws Exception {
Scanner s = new Scanner(System.in);
String n = s.nextLine();
StringBuilder sb = new StringBuilder(n);
for(int index = 0; index < sb.length(); index++)
{
char c = sb.charAt(index);
if(Character.isLowerCase(c))
{
sb.setCharAt(index, Character.toUpperCase(c));
}
else
{
sb.setCharAt(index,Character.toLowerCase(c));
}
}
System.out.println(sb);
}
}