1.写个程序实现0,1,1,2,3,5.......的数列,注意当求第10000个等大级数的情况,要求输入第几个数,得到结果.
package jianweiSoftware;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class FacbiooNumber {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int b;
double c;
String str;
System.out.println("请输入要得到的第几个FacbiooNumber:");
BufferedReader d =new BufferedReader(new InputStreamReader(System.in));
str = d.readLine();
b=Integer.parseInt(str);
System.out.print(b);
System.out.println("结果是:");
c = facbiooNumber(b);
System.out.print(c);
}
private static double facbiooNumber(int b) {
// TODO Auto-generated method stub
double x[] = new double[3];
if (b == 1) {
x[0] = 0;
return x[0];
}
if (b == 2) {
x[1] = 1;
return x[1];
}
if (b >= 3) {
x[0] = 0;
x[1] = 1;
for (int i = 3; i <= b; i++) {
x[2] = x[1] + x[0];
if ((i - 1) % 2 == 0) {
x[0] = x[2];
} else {
x[1] = x[2];
}
}
}
return x[2];
}
}
2.重写一个推栈类,其中包括push(Object item),pop(),peek(),empty().
package jianweiSoftware;
import java.util.EmptyStackException;
import java.util.Stack;
import java.util.Vector;
public class StackNew {
static Vector a = null;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public static Object push(Object item) {
a.addElement(item);
return item;
}
public static Object pop() {
Vector obj;
int len = a.size();
obj = (Vector) StackNew.peek();
a.removeElementAt(len - 1);
return obj;
}
public static Object peek() {
int len = a.size();
if (len == 0)
throw new EmptyStackException();
return a.elementAt(len - 1);
}
public boolean empty() {
return a.size() == 0;
}
}
要求20分钟内完成.
面试后觉得第一题还有点意思,在学校的时候不会考虑内存和大级数的情况,做题的时候花了点时间想想.第二题不知道公司想考察什么,也不知道自己这样写是否正确.反正两题答完十分钟.
好久没有在纸上写程序了,发现有点问题,还需要改进,平时太依赖IDE了,很的多小细节没有受到太多的关注.