File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Write a program which swaps letters' case in a sentence. All non-letter characters should remain the same.
3
+ */
4
+
5
+ import java .io .*;
6
+ public class Main {
7
+ public static void main (String [] args ) throws IOException {
8
+ File file = new File (args [0 ]);
9
+ BufferedReader br = new BufferedReader (new FileReader (file ));
10
+ String line ;
11
+ while ((line = br .readLine ()) != null ) {
12
+ for (int i = 0 ; i < line .length (); i ++) {
13
+ if (Character .isLowerCase (line .charAt (i ))) {
14
+ System .out .print (Character .toUpperCase (line .charAt (i )));
15
+ }
16
+ else if (Character .isUpperCase (line .charAt (i ))) {
17
+ System .out .print (Character .toLowerCase (line .charAt (i )));
18
+ }
19
+ else {
20
+ System .out .print (line .charAt (i ));
21
+ }
22
+ }
23
+ System .out .println ();
24
+ }
25
+ br .close ();
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments