一家公司的面试题求解.

lishengxf 2010-04-12 02:36:17
1. 用循环控制语句打印输出:1+3+5+…….+99=?结果。

2.编写两个方法分别计算组合数n!. 一个使用递归方法实现,另一个不用递归方法。

3. 编写如下的代码:
A. 这个数组应该有以下方法.
sort(Object[] a)
sort(Object[] o,Comparator c)
它们应该能对任何数据对象类型的数组进行排序。
find(Object[] o,Object b)
要求采用二分查找的方式,对排序后的数组,查找特定的元素.

B. 创建一个学生类,学生有如下属性
id(唯一), name,address,code,nickName,age

C. 创建一个具有10个学生类型元素的数组,首先根据id,利用ArraysUtil.sort(Object[] a)方法对它进行排序;然后,根据id,查找一个特定的学生(二分查找)。

D. 最后,再用sort(Object[],Comparator c)方法,对这个数组重新排序(先按姓名,再按地址排序的排序规则)。
...全文
548 44 打赏 收藏 转发到动态 举报
写回复
用AI写文章
44 条回复
切换为时间正序
请发表友善的回复…
发表回复
jmi443 2010-04-13
  • 打赏
  • 举报
回复
[Quote=引用 43 楼 liboofsc 的回复:]
不像是面试题,更像老师留的作业。
[/Quote]
哈哈,请LZ出来说明一下
liboofsc 2010-04-13
  • 打赏
  • 举报
回复
不像是面试题,更像老师留的作业。
sxcai 2010-04-12
  • 打赏
  • 举报
回复
学习中~~~~~~~~~~~~~~·
ydongxu 2010-04-12
  • 打赏
  • 举报
回复
学习拉~!!!!!!
sylibo 2010-04-12
  • 打赏
  • 举报
回复
好恐怖的!
yanyushancheng 2010-04-12
  • 打赏
  • 举报
回复
看来我还要加强学习。
无聊司马 2010-04-12
  • 打赏
  • 举报
回复
其它的不理解
只知道这么多:
import java.util.*;
class Student{
private int id;
String name;
//String adress;
//int age;
Student(int id,String name){
this.id=id;
this.name=name;
//this.adress=adress;
//this.age=age;
}
public int getId(){return id;}
public String getName(){return name;}
}
public class Testfind{
public static void main(String[] args){
int id;
System.out.println("请输入一个ID:");
Scanner input=new Scanner(System.in);
id=input.nextInt();
Student s[]=new Student [10];
s[0]=new Student(1,"adfbl");
s[1]=new Student(2,"a");
s[2]=new Student(3,"ad");
s[3]=new Student(4,"adj");
s[4]=new Student(5,"adfb");
s[5]=new Student(6,"adf");
s[6]=new Student(7,"adfblj");
s[7]=new Student(8,"adfblfgjh");
s[8]=new Student(9,"adfbldghfd");
s[9]=new Student(10,"adfbldfdfth");
switch(id){
case 1:System.out.println("adfbl");break;
case 2:System.out.println("a");break;
case 3:System.out.println("ad");break;
case 4:System.out.println("adj");break;
case 5:System.out.println("adfb");break;
case 6:System.out.println("adf");break;
case 7:System.out.println("adfblj");break;
case 8:System.out.println("adfblfgjh");break;
case 9:System.out.println("adfbldghfd");break;
case 10:System.out.println("adfbldfdfth");break;
default:
System.out.println("输入的ID有错误!!!");
}
}
}
无聊司马 2010-04-12
  • 打赏
  • 举报
回复
import java.util.*;
public class Testsort{
int []a;
public static int sort(int []a){
int temp=0;
for(int i=0;i<a.length;i++){
for(int j=0;j<a.length-1;j++){
if(a[i]<a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
return 0;
}

public static void main(String[] args){
int []a={1,5,3,6,2};
sort(a);
for(int k=0;k<a.length;k++){
System.out.print(a[k]+" ");
}
int []b=new int[5];
System.arraycopy(a,0,b,0,a.length);
Arrays.sort(b);
int j=3;
System.out.println("");
System.out.println("第四个数是:"+binarrysearch(b,3));
}
public static int search(int a[],int i){
for(int j=0;j<a.length;j++){
if(a[j]==i) return j;
}
return -1;
}
public static int binarrysearch(int a[],int i){
if(a.length==0)
return -1;

int start=0;
int end=a.length-1;
int m=(start+end)/2;

while(start<end){
if(i==a[m])
return m;
if(i>a[m]){
start=m+1;
}
if(i<a[m]){
end=m-1;
}
m=(start+end)/2;
}
return -1;
}
}
z_guijin 2010-04-12
  • 打赏
  • 举报
回复
sort是采用优化的快速排序算法对数组进行排序。。
如:Arrays.sort(a);
这样a数组的值会按从小到大排序后在存会数组a中
luqing414 2010-04-12
  • 打赏
  • 举报
回复
我很好奇B中Id如何唯一
ly248050 2010-04-12
  • 打赏
  • 举报
回复
为什么没书在手边我总是一阵心虚,会的也不会了...
lyh200731 2010-04-12
  • 打赏
  • 举报
回复
学习了······
gaokangstudy 2010-04-12
  • 打赏
  • 举报
回复
[Quote=引用 24 楼 keeya0416 的回复:]
上边的看不出来排序效果,下边的把数组的生产顺序改了下

Java code

public static void main(String[] args) {
Student[] s = new Student[10];
s[7] = new Student(23,"tom","beijing","aaaa","green");
s……
[/Quote]


是这样输出结果的吗?初学者我有点不懂,刚学了collection类
无聊司马 2010-04-12
  • 打赏
  • 举报
回复
第一题
public class Testfor{
public static void main(String[] args){
int sum=0;
for(int i=1;i<100;i+=2){
sum+=i;
}
System.out.println("sum="+sum);
}
}
wensefu 2010-04-12
  • 打赏
  • 举报
回复
基础题,都不需要用到什么难的算法.
wal812834184 2010-04-12
  • 打赏
  • 举报
回复
接分走人!
snowwhite1129 2010-04-12
  • 打赏
  • 举报
回复
ilrxx 2010-04-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 justlearn 的回复:]
第二题

Java code

//递归
public long factorial(long num) {
if (num == 1 || num == 0) {
return 1;
}
return factorial(num-1)*num;
}

//循环
public l……
[/Quote]
dai_weitao 2010-04-12
  • 打赏
  • 举报
回复
都是很基础的题,我想只要是学过JAVA或C的,解决这个很简单
流水不腐小夏 2010-04-12
  • 打赏
  • 举报
回复
学习了
加载更多回复(24)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧