Java Common Test Applet

Source: Internet
Author: User

private static void Nineninemulittable () {/** * 9*9 multiplication table */for (int i = 1,J = 1; J <= 9; i++) {System.out.print (i+ "*" +j+ "=" +i*j+ ""); if (i==j) {i=0;j++; System.out.println ();} }}/** * Determines whether the prime number 12=2*6=3*4 false * @param num prime number can only be divisible by 1 and he itself * @return */private static  boolean isprimenumber (int num) {for (int i=2;i <= math.sqrt (num); i++) {if (num% i = = 0) {return false;}} return true;} /** * Recursive calculation factorial 4*3*2*1 * @param num * @return */private static int f (int num) {if (num = = 1) {return 1;} Return num * f (num-1);}

/**
* "Narcissus"
*/
private static void Flower () {
for (int m=101;m<1000;m++) {
int b1 = m/100;
int b2 = M%100/10;
int b3 = m%10;
int n = b1*b1*b1+b2*b2*b2+b3*b3*b3;
if (M = = N) {
System.out.println ("--" +m);
}
}
}

Fibonacci sequence

Classical question: There are a pair of rabbits, from the 3rd month after birth a pair of rabbits each month, the small rabbit to the third month after the birth of a pair of rabbits each month, if the rabbit is not dead, ask the total number of rabbits each month?

         /** * Method One, using intermediate variables, assigned to the nearest first two numbers   */int f1 = 1, F2 = 1, F, m=24;      for (int i=3; i<=m; i++) {       f = f2;        F2 = f1 + F2;       F1 = f;        System.out.println ("First" + i + "rabbit logarithm of the Month:" +f2);          }        /** * Method Two, recursive method */private static int fun (int m) {if (m<3) {return 1;} Else{return Fun (m-1) +fun (m-2);}}        

Common sorting methods:

/** * Bubble Sort * Compare adjacent two numbers, place decimals in front, large number on back   * stability   * time complexity O (n^2)   * Less than heap sort, quick sort O (Nlogn, base 2)   * @param array * /private static void  Buddlesort (int[] array) {for (Int. I=1;i < array.length;i++) {for (int j=0;j<array.length-i ; j + +) {int temp;if (array[j] > array[j+1]) {temp = Array[j];array[j] =array[j+1];array[j+1] = temp;}}} /** * Select sort * @param array */private static void Selectsort (int[] array) {for (int. i=0;i<array.length-1;i++) {for (int j=i+1 ; j<array.length;j++) {int temp;if (Array[i] > Array[j]) {temp = Array[j];array[j] =array[i];array[i] = temp;}}}

  

/** * Binary search algorithm, if ordered * @param args */private static int binarysearch (int[] array, int num) {int low =0;int high = Array.len Gth-1;while (Low <= high) {int mid = (low + high)/2;if (num > Array[mid]) {low = Mid +1;} else if (num < Array[mid]) {high = mid-1;} Else{return Mid;}} return-1;}

  

 

Java Common Test Applet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.