尖微软件(上海)有限公司面试题

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了,很的多小细节没有受到太多的关注.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值