Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Rot-13/Java/rot-13.java
Normal file
33
Task/Rot-13/Java/rot-13.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import java.io.*;
|
||||
|
||||
public class Rot13 {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length >= 1) {
|
||||
for (String file : args) {
|
||||
try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
|
||||
rot13(in, System.out);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rot13(System.in, System.out);
|
||||
}
|
||||
}
|
||||
|
||||
private static void rot13(InputStream in, OutputStream out) throws IOException {
|
||||
int ch;
|
||||
while ((ch = in.read()) != -1) {
|
||||
out.write(rot13((char) ch));
|
||||
}
|
||||
}
|
||||
|
||||
private static char rot13(char ch) {
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
return (char) (((ch - 'A') + 13) % 26 + 'A');
|
||||
}
|
||||
if (ch >= 'a' && ch <= 'z') {
|
||||
return (char) (((ch - 'a') + 13) % 26 + 'a');
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue