九九乘法表和冒泡排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_35790330/article/details/70049934

今天无聊时想来写一下九九乘法表和冒泡排序,为以后面试做个准备,虽然很简单,额也算是小小的递归吧。

1.九九乘法表

public static void main(String[] args) {
		out(1,1);
	}
	
	public static void out(int i,int k){
		if(i<10){
			if(k <= i){
				System.out.print(i+"*"+k+"="+i*k+"  ");
				k++;
				out(i, k);
			}else {
				System.out.println("");
				i++;
				out(i,1);
			}
		}
	}

2.冒泡排序

public static void main(String[] args) {
		int ints[] = { 67, 69, 75, 98, 89, 90, 12, 100 };

		sort(ints, ints.length-1, 1);

		for (int a = 0; a < ints.length; a++) {
			System.out.print(ints[a] + "\t");
		}

	}

	public static void sort(int ints[], int i, int j) {
		if(i>0){
			if (ints[j] > ints[j - 1]) {
				int temp = ints[j];
				ints[j] = ints[j - 1];
				ints[j - 1] = temp;
			}
			
		if(j>=i){
			i--;
			sort(ints, i, 1);
		}else {
			j++;
			sort(ints, i, j);
		}
		}
	}



猜你喜欢

转载自blog.csdn.net/weixin_35790330/article/details/70049934