摘要:
for(int i = 1; i <= 9; i++){ for(int x = 1; x <= i; x++){ System.out.print(x + "*" + i + "=" + x*i +"\t"); } System.out.println();}运行结果: 1*1=1 1*2=2 2*2=4 1*3=3 2*3=6 3*3=9 1*4=4 2*4=8 3*4=12 4*4=16 1*5=5 2*5=10 3*5=15 4*5=20 5*5=25 1*6=6 2*6=12 3*6=18 4*6=24...
阅读全文
摘要:
费波那西数列,又译费波拿契数、斐波那契数列、费氏数列、黄金分割数列。在数学上,费波那西数列是以递归的方法来定义:用文字来说,就是费波那西数列由0和1开始,之后的费波那西系数就由之前的两数相加。0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610, 987, 1597, 2584, 4181, 6765, 10946,………………0不是第一项,而是第零项。public class Fib { public static void main(String[] args) { for(int i = 1;i < 21; i++){ ...
阅读全文
摘要:
临近的数字两两进行比较,按照从小到大或者从大到小的顺序进行交换,最大或最小的数字被交换到了最后一位,int[] array = new int[]{10,11,9,8,15,1,7,10,13,20};public void bubbleSort(int[] array){ int temp; for(int i = 0;i i;j--){ if(array[j] < array[j-1]){ temp = array[j]; array[j] = array[j-1]; array[j-1] = tem...
阅读全文