day004--20150804

Source: Internet
Author: User

Review:
1. Operators and expressions
1) Arithmetic: +-*/%,++,--
2) Relationship: >,<,>=,<=,==,!=
3) Logic: &&,| |,!
4) Assignment: =,+=,-=,*=,/=,%=
5) String Connection: +
6) Three Mesh/condition: Boolean? Number 1: Number 2
2. Branching structure
1) if:1
2) If...else:2
3) If...else if: multiple
4) Switch...case: Many
Advantages: Clear structure and high efficiency
Cons: Integers, equal
Break: Jump out of switch


Schoolboys
1. Loops: Repeatedly executing the same or similar code
2. Cyclic three elements:
1) Initialization of cyclic variables
2) Conditions of the loop (based on the cyclic variable)
3) changes in cyclic variables (toward the end of the cycle)
Loop variable: The amount of change in the loop
3. Loop structure:
1) While: first judgment after execution, it is possible not to execute at once
2) Do...while: First execution after judgment, at least once
Tip: When the 1th element is the same as the 3rd element, the preferred
3) for: Highest application rate
4.break: Jump out of the loop
Continue: Skips the remaining statements in the loop body and goes to the next loop

tasks: 1. Random addition arithmetic 2. Classic case not very well written down, redo once 3. Homework after Class 4. Daily practice

After-school assignment 9th series summation requirements: Output only the final result is OK

Addition

Randomly generate random numbers from 0 to 88

(int) (Math.random () *89)

(1) 5+85=?-----------------the question to calculate it! ---------------------------the answer to the question------------------------sentence

(2) 8+2=? Count It! 10 is right.

(3) 87+54=? Count It! 100 wrong.

..... score=40

do{
SYSTEM.OUT.PRINTLN ("Guess!");
Guess = Scan.nextint (); 1,3
if (guess==0) {
Break
}else if (guess>num) {
System.out.println ("Big up");
}else if (guess<num) {
System.out.println ("small");
}
}while (Guess!=num);

int num = 250;    The number of the stored loop variable: The number of guesses the user guessed 1) System.out.println ("Guess!"); int guess = Scan.nextint ();    2) Guess!=num 3) System.out.println ("Guess!"); Guess = Scan.nextint ();

To assign a value to a variable, there are three ways:
1) int num = 250;
2) int num = Scan.nextint ();
3) int num =?;

Requirement: num is a random number between 1 and 1000

Math.random ()------------------0 to 0.999999999 ..... *1000----------------------------0 to 999.9999999 ... +1----    ----------------------------1 to 1000.999999 .... (int)------------------------------1 to 1000

Math.random ()------------------0 to 0.999999999 .... *1000----------------------------0 to 999.9999999 .... (int)------------------------------0 to 999 +1--------------------------------1 to Math.random ()-----------------    -0 to 0.999999999 .... *1000----------------------------0 to 999.9999999 ..... (int)------------------------------0 to 999 +1--------------------------------1 to 1000

Implemented in three steps:
1. First and three elements
2. Big or small contrast tips
3. Enter 0 o'clock to exit

Guessinggame

Guess it! 200 is small.

Guess it! 300 big.

Guess it! 260 big.

Guess it! 249 is small.

Guess it! 250 Congratulations, you guessed it.

Print 10 copies of your CV
Number of copies

Enough for 10 copies? Not enough to make a copy of the number 1
Enough for 10 copies? Not enough to make a copy of the number 2
Enough for 10 copies? Not enough to make a copy of the number 3
Enough for 10 copies? Not enough to make a copy of the number 4
Enough for 10 copies? Not enough to make a copy of the number 5
Enough for 10 copies? Not enough to make a copy of the number 6
Enough for 10 copies? Not enough to make a copy of the number 7
Enough for 10 copies? Not enough to make a copy of the number 8
Enough for 10 copies? Not enough to make a copy of the number 9
Enough for 10 copies? Not enough to make a copy of the number 10
Enough for 10 copies? That's enough
Loop variable: Number of copies times
1) int times=0;
2) times<10
3) times++;
Times=0/1/2/3/4/5/6/7/8/9

Case 1: Output 10 times "action is the ladder of success"
Action is the ladder of success
Action is the ladder of success
Action is the ladder of success

...
Action is the ladder of success
Action is the ladder of success
Loop variable: times of output
1) int times=0;
2) times<=9
3) times++;
Times=0/1/2/3/4/5/6/7/8/9
Case 2: Multiplication table for output 9

1*9=9
2*9=18
3*9=27
4*9=36
...
9*9=81
Loop variable: Multiplier num
1) int num=1;
2) num<=9
3) num++;
Num=1/2/3/4/5/6/7/8/9

9*9=81
8*9=72
...
1*9=9
Loop variable: Multiplier num
1) int num=9;
2) Num>=1
3) num--;
Num=9/8/7/6/5/4/3/2/1


1) Sequential structure: Execute from top to bottom, every sentence must go
2) Branching structure: Conditional execution of a statement once, not every sentence must go
3) Loop structure: Conditional execution of a statement multiple times, not every sentence must go

while (Boolean) {
Statement block----loop body (code that executes repeatedly)
}
System.out.println ("over");

if (Boolean) {statement block} System.out.println ("over");

Repeated--------
Every year, Four seasons.
Every week, Monday to Sunday.
Every day, day and night.
Every Monday to Friday, Dahne to work.
Every Monday to Saturday.
Run 3 laps
Print 10 copies of the printer's CV

NT a=8,b=55; Ascending---a=5,b=8
if (a>b) {
int t=a; T=8
A=b; A=5
b=t; B=8//Exchange two number of small algorithms (rear-end and round)
}

A>b Change, guarantee a<b

int a=45,b=3,c=6,d=56; a=3,b=6,c=45,d=56

If the a>b exchange, to ensure that the a<b if a>c exchange, to ensure that a<c if a>d exchange, to ensure a<d if b>c exchange, to ensure b<c if b>d exchange, to ensure b<d if c>d exchange, to ensure that C <d

The number of days is mainly related to month

1/3/5/7/8/10/12-----------31 days 4/6/9/11--------------------30 days 2-----------------------------28 days/29 days

day004--20150804

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.