Java Beginner Learning (i)

Source: Internet
Author: User

One. Development environment

Developed with Eclipse. The steps are as follows:

Create a class under Create package->package under PROJECT->SRC;

Two. Variables and constants

1. Keywords, identifiers are not named

2. Data type

  

String--> string

3. Data type Conversion

Automatic: High precision to low precision loss of information.

Mandatory: (Data type)

4. Notes

Single-line Comment:

//...

Multi-line Comments:

/*  ...

*   ...

*/

Documentation notes:

/**  ...

*   ...

*/

Three. Operator

1. Arithmetic operators

  

2. Assignment operators

  

3. Comparison operators

  

4. Logical operators

  

5. Conditional operators

(Boolean) ? (true): (false)

6. Bitwise operators

| or

& and

^ XOR or

Four. Process Control Statements

1. Conditions

1.1 Items If

A:

if (...)

...;

B:

if (...)

...;

else if (...)

...;

Else

...;

1.2. Switch of condition

Switch ... {    //... to int or char

Case ...:

...;

Break

Case ...:

Case ...:

...;

Break

Defult:

...;

}

2. Cycle

2.1 Cycle of While

while (...)

{

...;

}

2.2 Cycle of Do-while

Do

{

...;

}while (...);

2.3 Loop for

for (...; ...; ...)

{

...;

}

3. Jump

Break

Continue

Five. Array

1. How to define

(a).

Int[] score; Statement

int score[];

Score = new INT[10]; Allocate space

(b).

Int[] score = new INT[10]; Declaration, allocating space

(c).

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

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

2. How to assign a value

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). Array converted to Characters

The method joins multiple array elements sequentially, separated by commas and spaces between multiple elements

Arrays.tostring (array name);

5. Two-dimensional array

Like a one-dimensional array, change [] to [].

Six. 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, the method's parameter type, the number, the order is different.

3. Note

You must create the object in the main function before you can invoke the method.

Seven. Input/Output

1. Output

System.out.println (); Line break

System.out.print (); No Line break

Shortcut keys:

syso-->alt+///system.out.println ();

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

2. Enter

(a). Import package Java.util.Scanner, under Packages

      Import Java.util.Scanner;

(b). Create a Scanner object, inside the main function

Scanner input=new Scanner (system.in);

(c). Input

int Score=input.nextint ();

Eight. Programming examples

Implements the number of inputs n, representing the total number of scores, followed by entering n integers, indicating the score, sorting the scores, and outputting the top three valid. (valid means within 0-100, including 0 and 100)

  

import Java.util.arrays;import Java.util.Scanner; Public classHelloWorld {//complete the Main method     Public Static voidMain (string[] args) {Scanner input=NewScanner (System.inch); HelloWorld Hello=NewHelloWorld (); intscores[]=New int[ -]; intn=Input.nextint ();  for(intI=0; i<n;i++) {Scores[i]=Input.nextint ();    } hello.prsort (scores); }        //define the method to finish sorting the scores and output the top three functions     Public voidPrsort (int[] scores)        {Arrays.sort (scores); intk=0;  for(inti=scores.length-1; i>=0&&k<3; i--)        {            if(scores[i]> -|| scores[i]<0)                Continue; Else{System. out. println (Scores[i]); K++; }                        }    }}
View Code

Java Beginner Learning (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.