java最新笔试题(含参考答案)

java最新笔试题(含参考答案)


1. Identifying problems with the code
Can you identify any problems with the following C++ code? If so, how would you fix the problem(s)?

class LongArray; //Manipulates a variable number of long ints.
class Widget
{
public:
Widget();
~Widget();

void Add(long l); // Add a long to the array
void Transform(); // Perform transformation on the array
void Print(); // Print the array
private:
LongArray* pLongArray;
};

Widget::Widget()
{
pLongArray = new LongArray;
}

Widget::~Widget()
{
delete pLongArray;
}

// The members Add(), Transform(), and Print() are implemented
// elsewhere.
void DoSomething(Widget x)
{
x.Transform();
x.Print();
}

void main()
{
Widget x;

x.Add(200);
x.Add(210);
DoSomething(x);
// Continue working after transformation…
}

2. Writing a simple program
Please write a function in C++, that will check a number between 1 and 1000 and return the value 1, if the number is a prime number and return the value 0 otherwise.

3. Missionaries and cannibals crossing the river
Three missionaries and three hungry cannibals, all of the same weight, are travelling together. They arrive at a river and find a boat that can carry only two men at a time. The missionaries and cannibals get along well, but if at any time the cannibals outnumber the missionaries problems arise. How can they all get across the river without the cannibals outnumbering the missionaries?

4. Four men crossing the bridge
Four men travelling together arrive at a bridge after dark and wish to cross. The bridge is narrow and they decide that they must use a flashlight to cross. They have a single flashlight. Unfortunately, the bridge will only stand the weight of two men at a time. A crossing party, either 1 or 2 people, must have the flashlight with them. The flashlight can be walked back and forth, but it cannot be thrown. Each man walks at a different speed, and any pair crossing must cross at the slower man's pace. The four different men can cross (one way) in the following time:

1 minute
2 minutes
5 minutes
10 minutes

Can all men cross in 17 minutes? What is the minimum time needed for all four men to cross the bridge? How would you prove that?


第一题会crash,因为DoSomething函数会调用默认拷贝构造函数取得array指针并且在销毁栈时调用析构函数delete了array。




--------------------------------------------------------------------------------
  相关文章
  百度招聘在线笔试题2007-1-30 17:11:05
  Google面试的20题2007-1-11 23:25:19
  JAVA测试题 面试2007-1-6 19:05:33
  一道数据库的笔试题目2007-1-6 19:02:48
  某公司的面试试题 [软件工程]2007-1-6 19:01:29
  博彦 笔试题 [软件工程师]2007-1-6 19:00:23
  通讯公司的面试题目2007-1-6 18:58:28
  一道测试notepad笔试题2007-1-6 18:57:36
  大公司笔试题2007-1-6 18:49:01
  某数据集团数据库初试笔试题2007-1-4 17:42:50
Google
分类: C#,Java,Asp.Net,PHP 面试题 日期:2007-2-17 查看:1