Java beginners (1): java beginners

Source: Internet
Author: User
Tags bitwise operators

Java beginners (1): java beginners

I. Development Environment

Developed Using eclipse. The procedure is as follows:

Create project> src create package> package create class;

II. Variables and constants

1. the keywords and identifiers cannot be named.

2. Data Type

  

String --> String

3. Data Type Conversion

Automatic: high-precision low-precision information loss.

Mandatory: (data type)

4. Notes

Single line comment:

//...

Multi-line comment:

/*...

*...

*/

Document notes:

/**...

*...

*/

3. Operator

1. Arithmetic Operators

  

2. Value assignment operator

  

3. Comparison Operators

  

4. logical operators

  

5. Conditional Operators

(Boolean )? (True) :( false)

6. bitwise operators

| Or

&

^ Exclusive or

4. Process control statement

1. Conditions

1.1 if

A:

If (...)

...;

B:

If (...)

...;

Else if (...)

...;

Else

...;

1. 2. switch of conditions

Switch... {//... Is int or char

Case ...:

...;

Break;

Case ...:

Case ...:

...;

Break;

Defult:

...;

}

2. Loop

2.1 loop while

While (...)

{

...;

}

2.2 loop do-while

Do

{

...;

} While (...);

2.3 loop

For (...;...;...)

{

...;

}

3. Jump

Break;

Continue;

5. Array

1. Definition Method

().

Int [] score; // statement

// Int score [];

Score = new int [10]; // allocate space

(B ).

Int [] score = new int [10]; // declare and allocate space

(C ).

Int [] score = {...}; // declare, allocate space, assign value

Int [] score = new int [] {...}; // declare, allocate space, assign value

2. Assignment Method

Scores [I] = x;

3. Iteration

For (int I = 0; I <scores. length; I ++ );

For (int I: scores );

4. Arrays class

Import java. util. Arrays; // import Arrays

(A). Sort

Arrays. sort (array name );

(B). convert an array to a character.

This method concatenates multiple array elements in order. Multiple elements are separated by commas (,) and spaces.

Arrays. toString (array name );

5. Two-dimensional array

Similar to a one-dimensional array, you can change [].

Sat. Method

1. Format

Access modifier return type method name (parameter list)

{

Method body

}

2. Method Overloading

In the same class, the method name is the same, and the parameter type, number, and order of the method are different.

3. Note

You must create an object in the main function before calling the method.

7. Input and Output

1. Output

System. out. println (); // line feed

System. out. print (); // do not wrap

Shortcut Key:

Syso --> Alt + // System. out. println ();

Main --> Alt + // public static void main (String [] args ){}

2. Input

(A). Import the package java. util. packages under the package.

Import java. util. collections;

(B). Create a struct object in the main function.

Wrote input = new partition (System. in );

(C). Input

Int score = input. nextInt ();

8. Programming example

Input n indicates the total number of scores. Then, input n Integers to indicate scores, sort the scores, and output the top three valid scores. (Valid means 0-100, including 0 and)

  

Import java. util. arrays; import java. util. finished; public class HelloWorld {// complete the main method public static void main (String [] args) {completed input = new completed (System. in); HelloWorld hello = new HelloWorld (); int scores [] = new int [100]; int n = input. nextInt (); for (int I = 0; I <n; I ++) {scores [I] = input. nextInt ();} hello. prsort (scores);} // define the method to sort the scores and output the top three functions public void prsort (int [] scores) {Arrays. sort (scores); int k = 0; for (int I = scores. length-1; I> = 0 & k <3; I --) {if (scores [I]> 100 | scores [I] <0) continue; else {System. out. println (scores [I]); k ++ ;}}}}View Code

 

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.