为了账号安全,请及时绑定邮箱和手机立即绑定

【java*编程】请教各位高手下面两个程序怎么写(java语言)?

【java*编程】请教各位高手下面两个程序怎么写(java语言)?

修养生息的Lueasy 2016-11-09 10:17:02
  1、编写一个Java应用程序:Ex3_1.java,对下面的明文进行加密处理并输出:“OPERATION OVERLORD: THE NORMANDY LANDINGS WILL TAKE PLACE ON JUNE  6th ,1944,AT 6:30”加密规则如下:1)  大写英文字母转换为该字母后序第五字母,如A转换为F、B转换为G;超出了字母Z,则循环到A开始,如X转换为C2)  数字符转换为该数字符后续第三数字符,如0转换为3,1转换为4;超出了数字符9,则循环到0开始,如8转换为12、编程Ex3_3.java:给定字符串“The past is gone and static. Nothing we can do will change it. The future is before us and dynamic. Everything we do will affect it.”,请统计指定单词“we”出现的频率(次数),并将单词“we”全部改成“you”。
查看完整描述

1 回答

?
蜂之谷

TA贡献564条经验 获得超863个赞

public static void demo1(String str){
		if(str == null || str.trim().length() == 0){
			System.out.println("参数错误");
			return;
		}
		String newStr = "";
		for (int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if (Character.isUpperCase(c)) {
				char c1;
				if(c == 'V'){
					c1='A';
				}else if(c == 'W'){
					c1='B';
				}else if(c == 'X'){
					c1='C';
				}else if(c == 'Y'){
					c1='D';
				}else if(c == 'Z'){
					c1='E';
				}else{
					c1 = c+=5;
				}
				newStr += c1;
			}else if(Character.isDigit(c)){
				
				char c2;
				if(c == '7'){
					c2='0';
				}else if(c == '8'){
					c2='1';
				}else if(c == '9'){
					c2='2';
				}else{
					c2 = c+=3;
				}
				newStr += c2;
			}else{
				newStr += c;
			}
		}
		System.out.println(newStr);
	}

超出字母或数字暂时没想到好的办法

public static void demo2(String str){
		String[] arr = str.replace(".", "").split(" ");
		int count = 0;
		for (int i = 0; i < arr.length; i++) {
			//System.out.println(arr[i]);
			if (arr[i].equals("we")) {
				count++;
			}
		}
		str = str.replace("we", "you");
		System.out.println("we出现次数:"+count);
		System.out.println("替换后:"+str);
	}


查看完整回答
反对 回复 2016-11-09
  • 1 回答
  • 0 关注
  • 1873 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信