2个回答
2015-11-10
展开全部
import java.util.*;
public class Yugi{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(true){
System.out.println("输入一行字母: ");
String line = scan.nextLine();
if(!line.matches("^[a-zA-Z]+$")){
System.out.print("输入错误, ");
continue;
}
String result = "";
for(int i = 0; i < line.length(); i++){
result += (char)((int)(line.charAt(i)) + 1);
}
System.out.println(result);
}
}
}
展开全部
public class Test {
public static void main(String[] args) {
String str = "hello world!";
String mima = encode(str);
System.out.println(mima);
}
public static String encode(String text){
String result;
char[] chars = text.toCharArray();
char[] chRes = new char[chars.length];
for(int i = 0; i < chars.length; i++){
if((chars[i] >= 'A' && chars[i] < 'Z') || (chars[i] >= 'a' && chars[i] < 'z')){
chRes[i] = (char) (chars[i] + 1);
}else if(chars[i] == 'z'){
chRes[i] = 'a';
}else if(chars[i] == 'Z'){
chRes[i] = 'A';
}else{
chRes[i] = chars[i];
}
}
result = String.valueOf(chRes);
return result;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |