我是Java初学者,遇到了难题请朋友帮忙解决下,谢谢

1.String{76,54,73*,85,83,89}(使用冒泡排序法)

2.有50人排成一圈,其中以3和3的倍数抽出,输出其他人,并指出他们的位置。

3.表student,字段stu_id,stu_name,表class,字段cl_id,cl_name,表course,字段id,stu_id,cl_id,查出有2科以上的学生信息

感觉好难哦。。。。谢谢解答。

这些题目没有什么实际应用意义,但是可以帮助你养成编程思想,所以代码就不给你写了,给你个思路,自己试试.
第一题 用嵌套循环
你那个数组就声明成string s[]吧,再声明变量 string a,b,temp="";int i=0;int j=i+1;
首先 第一重循环s[i]赋给a,然后进入第二重.
第二重循环,用a循环去和s[j]比大小,如果有比a大的,让temp=a a=b b=temp 第二重循环j++;
外部循环i++;
第二题
写个50次的循环,在循环体内判断i的值,如果i能整除3,那就是3或3的倍数,不做任何动作, 否则输出i的值.
第三题 我想的应该是麻烦了
查course表的stu_id 用while(rs.next())循环把所有查到的内容都放到一个数组里. 然后用冒泡排序的原理. 但是不是比大小了,而是看是否相等. 如果有相等的那说明这个id最少出现了2次(如果题目要求是2次以上不含2次的,你就可以再加个计数器来控制),只要一找到就把内循环break掉回到外循环,因为本次内循环的目的已经达到了. 拿着符合条件的stu_id 再去student表查出名字来 输出就好了 class表没用上.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-06-03
3:select * from student stu join course cou on stu.stu_id=cou.stu_id join class cla on cla.cl_id=cou.cl_id group by cl_name having count(cou.cl_id)>=2 这是效率最快的查询

2: public class Test5 {
private int i;
private int count=1;
public void method(int total){
List list=new ArrayList();
if(total<3) return;
System.out.println(".............第"+count++ +"圈比较...............");
for(i=1;i<=total;i++){
if(i%3==0){
System.out.println("能被3整除的数"+i);
}else{
list.add(i);
System.out.println("不能被3整除的数"+i);
}
}
method(list.size());
}
public static void main(String[] args){
new Test5().method(50);
}
}

3:public class QuickSort {

public int getPivot(int a[], int low, int high) {
int pivot = 0, temp;
temp = a[low];
pivot = a[low];
while (low < high) {
while (low < high && a[high] >= pivot) {
high--;
}
a[low] = a[high];
while (low < high && a[low] <= pivot) {
low++;
}
a[high] = a[low];
}
if (low == high) { // 这个判断属于废话,但是为了可读性

pivot = low; // pivot=high
a[pivot] = temp;
}
return pivot;
}

public void quickSort(int[] a, int low, int high) {

if (low < high) {
int pivot = this.getPivot(a, low, high);
quickSort(a, low, pivot-1);
quickSort(a, pivot + 1, high);
}

}

public static void main(String args[]) {

int a[] = {76,54,73,85,83,89};
new QuickSort().quickSort(a, 0, a.length - 1);
for (int num : a) {
System.out.println(num);
}
}
}

快速排序,冒泡排序最快的本回答被提问者采纳
相似回答