Bubble sort, select Sort, Math,random,system

Source: Internet
Author: User
Tags array sort square root

Bubble sort
public class Mathgroup {
public static void Main (string[] args) {
Int[] arr= {13,43,25,36,45};
for (int x=0;x<arr.length-1;x++) {
for (int y=0;y<arr.length-1-x;y++) {
if (Arr[y]>arr[y+1]) {
int num=arr[y];
ARR[Y]=ARR[Y+1];
Arr[y+1]=arr[y];
}
}
}
SYSTEM.OUT.PRINTLN ("Array sort result is:");
GeSHi (arr);
}
public static void GeSHi (int[] a) {
System.out.print ("[");
for (int i=0;i<a.length;i++) {
if (i==a.length-1) {
System.out.print (a[i]+ "]");
}else {
System.out.print (a[i]+ ",");
}
}
}
}

Select sort
public class Choolse {
public static void Main (string[] args) {
Int[] arr= {13,43,25,36,45};
for (int x=0;x<arr.length;x++) {
for (int y=0;y<arr.length;y++) {
if (Arr[x]>arr[y]) {
int num=arr[x];
Arr[x]=arr[y];
Arr[y]=num;
}
}
}
System.out.println (arrays.tostring (arr));
}
}

Math:
public static int abs (int a)
Gets the absolute value of the given data
public static double Ceil (double A)
Gets the smallest double integer that is larger than the given data
public static double floor (double a)
Gets the largest integer of type double, which is smaller than the given data
public static int max (int a,int b)
Get the maximum value in two numbers
public static Double pow (double a,double b)
Returns a power of B
public static double Random ()
Generate a random number between [0.0-1.0]
public static int round (float a)
Rounded
public static double sqrt (double A)
Positive square root
Random:
public int Nextint ()
Get a random number in the INT range
public int Nextint (int n)
System
Get a random number between 0 and N [n]
public static void GC ()
Garbage collector
public static void exit (int status)
Terminating a currently running Java Virtual machine
public static long Currenttimemillis ()
Gets the millisecond value of the difference between the current system time and 1970-01-01 00:00:00

Bubble sort, select Sort, Math,random,system

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.