有一道加密的题目 大致上是:
输入一段字符串 例如 hello,world!
加密方法,每个字母按照字母排序表后移三位,如 abc 后移三位def hell,world! 加密输出就是khoo,ziuog!
如果有数字 则数字不变,标点符号不变。求解:
输入字符串传 如hell,world!
1. 如何进行比对?
2.int类型可以用求余方法进行分解,字符串如何把字符串分解成一个一个的字符?
3.字符串分解后如何判断是数字还是标点符号?
本人是新手,麻烦各位代码简单化哈 太复杂看不懂~~~辛苦各位前辈啦
输入一段字符串 例如 hello,world!
加密方法,每个字母按照字母排序表后移三位,如 abc 后移三位def hell,world! 加密输出就是khoo,ziuog!
如果有数字 则数字不变,标点符号不变。求解:
输入字符串传 如hell,world!
1. 如何进行比对?
2.int类型可以用求余方法进行分解,字符串如何把字符串分解成一个一个的字符?
3.字符串分解后如何判断是数字还是标点符号?
本人是新手,麻烦各位代码简单化哈 太复杂看不懂~~~辛苦各位前辈啦
解决方案 »
- [向所有提问]安装properties插件时,在Link文件夹中.无法新建一个扩展名为link文件是怎么回事?,
- 有关子类对象指向父类引用
- 向大家请教一个数据结构算法问题!!
- 再次请教个问题,关于==
- 三个变量a,b,c。如果a.equals(b) 同时 b.equals(c)返回都是True,那么是否总是c.equals(a)?
- InstallAnywhere 把java swt制成安装包
- 请问如何在java中导如入用3DMAX做成的.MAX模型???
- 关于数据库的插入
- 帮帮忙,找张光盘!!!
- 急急急***VJ++的安装系统不兼容问题***
- 现在企业里java GUI编程最常用的是swing还是swt,或者其它?
- 编码转换,能再麻烦点么?
import java.util.Scanner;public class Test {
public static void main(String[] args) throws Throwable {
StringBuilder stringBuilder = new StringBuilder();
System.out.println("Input a string:");
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
int loops = s.length();
char c;
for (int i = 0; i < loops; i++) {
c = s.charAt(i);
if (c >= 'a' && c <= 'z') {
c += 3;
if (c > 'z') c -= 'a';
} else if (c >= 'A' && c <= 'Z') {
c += 3;
if (c > 'Z') c -= 'A';
}
stringBuilder.append(c);
}
System.out.println(stringBuilder.toString());
}
}
for (int i = 0; i < loops; i++) {
c = s.charAt(i);
if (c >= 'a' && c <= 'z') {
c += 3; //这里是字符 为什么直接+3 字符就后移3位?
if (c > 'z') c -= 'a';
} else if (c >= 'A' && c <= 'Z') {
c += 3;
if (c > 'Z') c -= 'A';
}
String str = "hello,world";
Char[] charArray = str.toCharArray();
下面楼主应该会了吧~~
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
//String str="hello,world!";
int n=0;
char ch;
for(int i=0;i<str.length();i++){
ch=str.charAt(i);
n=ch;
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')){
n=n+3;
}
System.out.print((char)n);
} }}