*设为首页
*加入收藏
热门关键字: JAVA
>>当前位置:Java大本营>认证考试>文章内容
java最新笔试题
作者: 发布时间:2007-12-14 15:40:31
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。

·北大青鸟JAVA面试题(04-24)
·Java程序员面试宝典:super类 (04-19)
·微软101道经典面试题 (03-24)
·今天的Java笔试题 (02-04)
·一些著名的大公司面试题目 (02-03)
·JAVA笔试改错题 (02-03)
·google的一道JAVA面试题(02-03)
·java程序员面试题(基础) (01-02)
·JAVA程序员面试32问(必备)(01-02)
·面试风云:与顶级CTO交手的难忘经验 (01-02)
·硅谷招聘流行搞怪试题 Google面试题答(01-02)
·java面试题 (01-01)
复制地址发给您的好友: [推荐文章] [返回顶部] [关闭窗口]
版权所有 Java大本营 1999-2007 转载请注明出处