输出大写字母字符串中每个大写字母之后的第5个字母所对应的小写字母



输出大写字母字符串中每个大写字母之后的第5个字母所对应的小写字母。如果超过了Z,超出了1,则输出a;超出了2,则输出b;依次类推。如A对应f,V对应a,Z对应e。

public class Main {
	public static void main(String[] args) {
		String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		solution(str);
	}

	public static void solution(String str) {
		char[] args = str.toCharArray();
		char res = ' ';
		for (int i = 0; i < args.length; i++) {
			if (args[i] >= 'A' && args[i] <= 'U') {
				res = (char) ((int) args[i] + 5 + 32); // 'a'的Ascii码为97,'A'的Ascii码为65。97-65=32
				System.out.print(res);
			} else {
				res = (char) (5 - (int) ('Z' - args[i]) - 1 + (int) 'a');
				System.out.print(res);
			}
		}
	}
}

输出结果

输出大写字母字符串中每个大写字母之后的第5个字母所对应的小写字母_第1张图片


你可能感兴趣的:(编程)