我改了一下:
import java.io.*; public class ROT13 {
public static void main(String[] args) throws IOException {
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String current=stdin.readLine();
int l=current.length();
int i=0;
char c=current.charAt(i);
for(i=0;i<l;i++) {
boolean flag=false;
while(c>=65&&c<=77||(c>=97&&c<=109)) {
c+=13;
System.out.print(c);
flag=true;
break;
}
if(!flag){
while(c>77&&c<=90||(c>109&&c<=122)) {
c-=13;
System.out.print(c);
break;
}
}
} }
}
import java.io.*; public class ROT13 {
public static void main(String[] args) throws IOException {
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String current=stdin.readLine();
int l=current.length();
int i=0;
char c=current.charAt(i);
for(i=0;i<l;i++) {
boolean flag=false;
while(c>=65&&c<=77||(c>=97&&c<=109)) {
c+=13;
System.out.print(c);
flag=true;
break;
}
if(!flag){
while(c>77&&c<=90||(c>109&&c<=122)) {
c-=13;
System.out.print(c);
break;
}
}
} }
}
刚开始学JAVA,不懂的东西很多,以后还请多多关照啊~怎样把int转成char?一直不清楚。
import java.io.*; public class ROT13 {
public static void main(String[] args) throws IOException {
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String current=stdin.readLine();
int l=current.length();
char c;
for(int i=0;i<l;i++) {
c=current.charAt(i);
if(c>=65&&c<=77||(c>=97&&c<=109)) {
c+=13;
System.out.print(c);
}
else if(c>77&&c<=90||(c>109&&c<=122)) {
c-=13;
System.out.print(c);
}
else
System.out.print(c);
} }
}
谢谢!
import java.io.IOException;
import java.io.InputStreamReader;public class Rot13 { public static void main(String[] args) {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
try {
String str = bf.readLine();
for(int i = 0 ; i< str.length() ; i++) {
char c = str.charAt(i);
if (c >= 'a' && c <='m' || c >= 'A' && c <= 'M') {
c += 13;
System.out.print(c);
} else if(c >= 'n' && c <= 'z' || c >='N' && c <= 'Z' ) {
c -= 13;
System.out.print(c);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.IOException;
import java.io.InputStreamReader;public class Rot13 { public static void main(String[] args) {
BufferedReader bf =
new BufferedReader(new InputStreamReader(System.in));
try {
String str = bf.readLine();
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c >= 'a' && c <= 'm' || c >= 'A' && c <= 'M') {
c += 13;
System.out.print(c);
} else if (c >= 'n' && c <= 'z' || c >= 'N' && c <= 'Z') {
c -= 13;
System.out.print(c);
}
} } catch (IOException e) {
e.printStackTrace();
}
}
}