Java-based output and sort

Source: Internet
Author: User
Today, I gave a lecture in Java 2nd. In the first half, I felt that those data types have been learned in C ++, So I first slipped away ~ When it came out, we saw heavy rain and the sun running at the same time ^_^.
When I came back and finished my homework, I had to go out of the border for half a day, but I didn't think it was very careful. It seems that you should never be careless when using programming ~

/*
Returns the square of the first 10 natural numbers.
Shawn
Citypw @ Copyright
*/
Class Square
{
Static int I, V;
Square ()
{
System. Out. println ("Welcome! ");
Show ();
}

Void show ()
{
For (I = 1; I <= 10; I ++)
{
System. Out. println (I * I); // system. Out. println is like the cout output stream in C ++.
}
}
Public static void main (string [] ARGs) // You must declare it as public static because only one of main is allowed.
{
Square S = New Square ();
}
}

/*
Sorted
Shawn
Citypw @ Copyright
*/
Class Test
{
Static int I, j, temp;
Test () {system. Out. println ("start sorting ");}
Void bubblesort (INT [])
{
// Use a bubble
For (I = 0; I <A. Length/3; I ++)
{
For (j = 0; j <A. Length-1; j ++)
{
If (A [J]> A [J + 1])
{
Temp = A [J];
A [J] = A [J + 1];
A [J + 1] = temp;
}
}
}
}

Public static void main (string [] ARGs)
{
Int [] arrayofints = {3,589, 622,127 };
Test T = new test ();
T. bubblesort (arrayofints );
For (INT I = 0; I <arrayofints. length; I ++) // print the result
System. Out. Print ("" + arrayofints [I]);
}
}

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.