2013年8月华为java机试题目

先吐槽一下。我是前段时间通过华为官方投的简历。华为最近几天有一轮招聘,通过短信形式通知的,让应聘者回复参加哪种语言,然后竟然没有确认收到信息。等了大概一周华为才通过短信通知去西工大老校区机试,有的没有收到短信。结果本来是下午三点开考,我一点半出发,两点就到了。结果等到了四点才开考!那么热的天,实在受不了了!无语! 考试题目就三道题: 1.给你一个int型数组,按降序排序。我就直接用的冒泡。 2.给你一个String字符串,比如 !!!###*%H***U///AWEI***”123!!! 过滤掉其中非字母和非数字的字符,然后将剩下的输出。 3.给你一个String,比如 aaabbddefasaaddd 返回数目最多的字符。如果有数目相同的字符,随机返回一个即可。 附上我自己写的代码:
package com.duapp.itfanr;

public class CharDemo {

	public static void main(String[] args) {

		String str = "abcdefabccrrrrehhhhhhhrrrcccc" ;

		System.out.println( "最多的字母之一为:"+"------------->"+getMostTimes(str ) ) ;

	}

	static char getMostTimes(String str ) {

		int len = str.length() ;
		StringBuffer sb = new StringBuffer(str.charAt(0)) ;
		for(int i=1; i<len; i++){			
			String strTemp = new String(sb) ;
			if(!strTemp.contains(String.valueOf(str.charAt(i)))) {
				sb.append(str.charAt(i)) ;				
			}			
		}
		String charAll = new String(sb) ;//得到去重时候的字符串
		int len2 = charAll.length() ;
		int []count = new int[len2];
		for(int i=0; i<charAll.length(); i++){
			count[i] = 0 ;

		}
		System.out.println(charAll) ;//统计个数
		for(int i =0;i<len; i++){
			for(int j =0; j<len2; j++){
				if(str.charAt(i)==charAll.charAt(j)){					
					count[j]++;  
				}
			}

		}
		for(int i = 0;i<len2; i++){
		System.out.println(charAll.charAt(i)+"的个数为-------------->"+ count[i]) ;
		}				

		int max = count[0]; //寻找最大值所在的位置
		int maxFlag = 0;
		for(int i = 0; i<len2 ; i++){
		   if(count[i]>max){
			   max = count[i] ;
			   maxFlag = i ;			   
		   }		    
		}		

		return charAll.charAt(maxFlag) ;
	}

}
结果如下:
bcdefarh
b的个数为-------------->2
c的个数为-------------->7
d的个数为-------------->1
e的个数为-------------->2
f的个数为-------------->1
a的个数为-------------->2
r的个数为-------------->7
h的个数为-------------->7
最多的字母之一为:------------->c
 

转载于:https://my.oschina.net/itfanr/blog/358452

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值