java-Bubble Sort

Source: Internet
Author: User

1. Printing

print--printing, no line break, add line breaks as required

println--Print once and wrap it up.

printf--printing, inherit C speech format, can be formatted output

Line break

' \ R ' is a carriage return, ' \ n ' is a newline, ' \ t ' is a tab

Method of use: 1. SYSTEM.OUT.PRINTLN ("Thank you for your support \ n");

2.SYSTEM.OUT.PRINTLN (i+ "*" +j=i*j+ "\ n");

2. Bubble sort

Used for array sorting, comparing the first and neighboring elements, sequentially comparing the number of adjacent neighbors, and the last one being the maximum number.

If there is n number, then the N-1 cycles;

Each cycle, 22 comparisons, the last element is no longer compared with the previous one.

for (int i=0;i<arr.length-1;i++) {
for (int j=0;j<arr.length-1-i;j++) {
if (Arr[j]>arr[j+1]) {
TEMP=ARR[J];
ARR[J]=ARR[J+1];
Arr[j+1]=temp;
}

}

}

3. Array new

int arr[]=new int[5];

4.Scanner input

Import Scanner Class Package

Sacnner input= New Scanner (system.in);

Arr[i]=input.nextint ();

java-Bubble Sort

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.