File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ class ToggleCase {
4+ // Main method
5+ public static void main (String [] args ) {
6+ Scanner input = new Scanner (System .in );
7+
8+ System .out .print ("Enter a string: " );
9+ String str = input .nextLine ();
10+
11+ // Method to toggle character case
12+ String result = toggleCharacterCase (str );
13+
14+ System .out .println ("String after toggling character case: " + result );
15+ }
16+
17+ // Method to toggle character case
18+ public static String toggleCharacterCase (String str ) {
19+ String result = "" ;
20+ for (int i = 0 ; i < str .length (); i ++) {
21+ char ch = str .charAt (i );
22+ if ((int ) ch >=65 && (int ) ch <= 90 ){
23+ result += (char ) ((int ) ch + 32 );
24+ } else if ((int ) ch >= 97 && (int ) ch <= 122 ){
25+ result += (char ) ((int ) ch - 32 );
26+ } else {
27+ result += ch ;
28+ }
29+ }
30+ return result ;
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments