mercury systems inc interview

Interview 1:

一个java的小测验, 包含10道判断题和两个编程题


1.     An abstract class must have at least one abstract method.  (F)

2.     Inheritance shows“is a” relation. (T)

3.     We can use try-finally block without catch clause. (T)

4.     StringBuilder is a thread-safe class. (F)

5.     ArrayList has better performance than Vector.(T)

6.     IOException is an unchecked exception. (T)

7.     A transient fieldcan not be serialized.(T)

8.     A constructor isa method that can only have return type void.(F)

9.     We can definepublic static final void main method. (T)

10.  clone() method inclass Object makes a deep copy of an object.(T)

做错了两个题目(未改正),因此只得了16/20

然后是两个编程题目:

Problem #1 (40 credits)

Given a string,design an algorithm in O(n) running time to find the character that appearsmore than half of the time in the string. If the character does not exist,output null.

Input:abadacababaaaa

Output: a

Input: abcdeabbad

Output: null

下面是我的程序,得分只有(30/40), 也不知道哪里出错了:

import java.util.HashMap;
import java.util.Scanner;
/**
 * 
 * Given a string, design an algorithm in O(n) running time to 
 * find the character that appears more than half of the time in the string. 
 * If the character does not exist, output null.
	Input: abadacababaaaa
	Output: a
	Input: abcdeabbad
	Output: null
 * @author 
 * 2014-2-13
 */
public class Question1 {

	public char moreThanHalfString(String s) {
		HashMap<Character, Integer> map = new HashMap<Character, Integer>();
		char result = '\u0000';
		int maxTimes = 0;
		for (int i = 0; i < s.length(); i++) {
			char temp = s.charAt(i);
			if (!map.containsKey(temp)) {
				map.put(temp, 1);
			} else {
				int currTimes = map.get(temp) + 1;
				if(currTimes > s.length()/2){
					return temp;
				}
				map.put(temp, currTimes);
				if (currTimes > maxTimes) {
					result = temp;
					maxTimes = currTimes;
				}
			}
		}
		if (maxTimes > s.length() / 2)
			return result;
		else
			return '\u0000';
	}

	public static void main(String[] args) {
		 System.out.println("If you want to quit, please input: q");
		Question1 question1 = new Question1();		
		String s = "";		
		Scanner input = new Scanner(System.in);
		while (true) {
			System.out.print("Input:");
			s = input.nextLine();
			if(s.equals("q")){
				break;
			}
			char result = question1.moreThanHalfString(s);
			System.out.print("Output:");
			if (result == '\u0000')
				System.out.println("null");
			else
				System.out.println(result);
		}
		
		System.out.println("End");
	}

}


Problem #2 (40 credits)

Input an arithmetic expression with ONLY +,-, * and /, parse the expression and calculate the result.

Input: 5.6 / 0.7 * 2 – 3.5

Output: 12.5

Input: -1.3 + 5.1 / 3 – 0.8

Output: -0.4

这题可以去到Data Structures & Algorithms in Java中参考下


Interview 2:

是个电话面试,面试的还好是个中国人,两个人用中式英语聊着也还能听懂,主要问的就是一些java的基本概念

1.abstract class 和 interface的区别

2.Exception handling

3.final class

4.finally block

5. difference between thread and runnable, which one is better?

6.garbage collection, how to invoke garbage

7.Difference between List and Set

...

能记住的就这么多了


就这么多了,忘有助于他人



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值