August 2013 Huawei java computer examination purposes

First Tucao about. I was some time ago by Huawei official vote resume. Huawei in recent days have a recruitment notification by text message, so that candidates participate in reply to which language, and then not even acknowledge receipt of the message. Huawei waited for about a week before as SMS to the old campus NPU test machine, and some did not receive text messages. The results could have been three in the afternoon the opening test, I set out one-thirty, two to go. The result until four o'clock in the opening test! Hot day, really I can not stand! Speechless! Exams on three questions: 1. give you an int array, sorted in descending order. I was bubbling with directly. 2. String give you a string, for example! ! ! ### *% H *** U /// AWEI *** "123 !!! filter out which non-alphabetic and non-numeric characters, then the rest of the output. 3. Give you a String, such as aaabbddefasaaddd return a maximum number of characters if the same number of characters, you can attach a random return code I wrote it myself:
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) ;
	}

}
The results are as follows:
bcdefarh
b的个数为-------------->2
c的个数为-------------->7
d的个数为-------------->1
e的个数为-------------->2
f的个数为-------------->1
a的个数为-------------->2
r的个数为-------------->7
h的个数为-------------->7
最多的字母之一为:------------->c
 

Reproduced in: https: //my.oschina.net/itfanr/blog/195644

Guess you like

Origin blog.csdn.net/weixin_33733810/article/details/91799610