99 Multiplication Table:
please use algorithmic program to make 99 multiplication table. ()
.
Its corresponding algorithm is
1 Public class99 multiplication Table {2 Public Static voidMain (string[] args) {3 for(inti=1;i<=9;i++){4 for(intj=1;j<=i;j++){5 inta=i*J;6System.out.print (i+ "*" +j+ "=" +a+ "");7 }8 System.out.println ();9 }Ten } One}
Bubble Sort:
Before bubbling the sort, look at a simple arrays method of sorting, the program is as follows:
1 Public Static voidMain (string[] args) {2 //first define an array3 int[] a={23,90,9,25,16,2};4 Arrays.sort (a);5 for(inti=0;i<a.length;i++) {6System.out.println (a[i]+ "");//positive sequence output, and from small to large7System.out.print (a[a.length-1-i]+ "");//reverse output, and from large to small8 }9}
Now there are 23,90,9,25,16,2 these six numbers, please use Bubble Sort the algorithm arranges the size.
1 Public classBubble Sort {2 Public Static voidMain (string[] args) {3 //first define an array4 int[] num={23,90,9,25,16,2};5 intTemp=0;6 for(inti=0;i<num.length-1;i++){7 for(intj=0;j<num.length-1-i;j++){8 if(Num[j]<num[j+1]) {//change the smaller to greater than the number is small to large row9temp=Num[j];TenNum[j]=num[j+1]; Onenum[j+1]=temp; A } - } - } the //Final Loop Output - for(inti:num) { - System.out.println (i); - } + } -}
the classic algorithm in Java, Narcissus algorithm :
Find the number of daffodils in 100-999, (if three digits abc,abc=a^3+b^3+c^3, it is called ABC is the number of daffodils.) such as 153,1^3+5^3+3^3=1+125+27=153, then 153 is the number of daffodils)!
1 Public classNarcissus algorithm {2 Static intA;3 Static intb;4 Static intC;5 Static intsum;6 7 Public Static voidMain (string[] args) {8 /*the number of daffodils in 100-999, (if three digits of abc,abc=a^3+b^3+c^3,9 the number of daffodils is called ABC. such as 153,1^3+5^3+3^3=1+125+27=153, then 153 is the number of daffodils)!*/Ten for(inti=100;i<=999;i++) {//153 OneA=i%10; AB=i/10%10; -c=i/100; -sum=a*a*a+b*b*b+c*c*C; the if(sum==i) { -System.out.println (i+ "is narcissus number!!")); - } - } + } -}
Bubble sort and narcissus algorithm and 99 multiplication table