Java learning notes: Java Process Control and java learning notes

Source: Internet
Author: User
Tags case statement sca switch case

Java learning notes: Java Process Control and java learning notes
I. Introduction

Java Process Control includesSequential Control, condition control, and cyclic control.

Sequential control means that each statement is executed from start to end in sequence. Conditional Control: select the execution statement based on the conditions. For example, if the condition is true, operation A is executed, or operation A is executed if the condition is true. Otherwise, Operation B is executed. Loop Control, also known as loop control, executes operations in the loop body according to the initial conditions and termination requirements of the loop.

The ordered structure can only be executed in sequence and cannot be judged or selected. Therefore, the branch structure is required.

Java has two branch structures:

  • If statement
  • Switch statement

Java has three main cycle structures:

  • While Loop
  • Do... While Loop
  • For Loop
Ii. Notes
Package com. hgd. study2; import java. util. workflow;/*** java Process Control: cyclical structure of the sequential structure points ** @ author HuTiger Sequence Structure: the debug mode shows the ** branch structure of the java program runtime Sequence Structure: if statement **/public class ProcessControl {public static void main (String [] args) {// IfStudy (); // SwitchCaseStudy (); // WhileStudy ();}/** IF statement */private static void IfStudy () {/** determines whether to enter the statement block if (condition expression) based on the world expressed by the condition (true | false) {statement block} continue executing the following statement */int I = 100; If (I> 60) {System. out. println (I);} System. out. println ("the statement to be executed later");/** if else statement * // system. in is the standard input. You can obtain the input value from the keyboard. // You can process the obtained data using the kernel (a tool provided by jdk) System. out. println ("Enter the score! "); Using SC = new using (System. in); int j = SC. nextInt (); // assign the number of user inputs to j System. out. println ("the value obtained by the console is:" + j); if (j> 60) {System. out. println ("passed");} else {System. out. println ("failed");} System. out. println ("content to be executed after if else execution");/** if else if... else * // scenario: divide a score: rating of 5 points A 4 = B 3 = C Others are D pipeline sca = new pipeline (System. in); int score = sca. nextInt (); if (score> = 0 & score <= 5) {if (score = 5) {System. out. println ("A");} else if (score = 4) {System. out. println ("B");} else if (score = 3) {System. out. println ("C");} else {System. out. println ("D") ;}} else {System. out. println ("invalid input");}/** exercise: percentile System 90-100 excellent 75-89 good 60-74 qualified other unqualified */percentile scan = new percentile (System. in); int score1 = scan. nextInt (); if (score1> = 0 & score1 <= 100) {if (score1> = 90 & score1 <= 100) {System. out. println ("excellent");} else if (score1> = 75) {System. out. println ("good");} else if (score1> = 60) {System. out. println ("qualified");} else {System. out. println ("unqualified") ;}} else {System. out. println ("invalid input") ;}/ ** switch case */private static void SwitchCaseStudy () {/** branch statement: switch case key: expression value to be compared: value to be compared with the expression * Execution Process: if the key and value compare result is true, the Code in the case section will be executed, the case section may have multiple items similar to the else if Section * The difference is that the comparison between the key and value can only be = default. The section does not meet any of the above Code, similar to else **, the expression value in the brackets following the switch must be a constant expression of the byte, char, short, and int types. After jdk1.7, you can use string *, rather than float or long ** switch (key) {case value: break; default: break;} * // scenario: divide a 5 (score): rating of 5 points A 4 = B 3 = C Others are D sort SC = new sort (System. in); int score = SC. nextInt (); switch (score) {case 5: System. out. println ("A"); break; // The standard statement break cannot be skipped from the current statement block. If no break exists, it will directly go to the next case statement case 4: System. out. println ("B"); break; case 3: System. out. println ("C"); break; default: System. out. println ("D"); break;}/** while loop and do while */private static void WhileStudy () {/** execution process: when the conditional expression is true, enter the code block and execute the code to be executed. When the conditional expression is false, run the following statement ** while (conditional expression) {code to be executed} The following statement * // ** scenario: Input 1-integer analysis: Give the output value a variable I, when I is between 1 and 100, the output */int I = 1; // the starting point of the loop while (I <=) {System. out. println (I); // The cyclic step I ++;} System. out. println ("Print end");/** do while ** do {*} while (conditional expression) */int a = 1; do {// the content in the statement block will first execute System no matter whether the conditions are met or not. out. println (a); a ++;} while (a <= 0);}/** for loop */private static void ForStudy () {/** scenario: print 1-100 int I = 1 is the starting point of the loop I ++ loop compensation I <= 100 condition of the loop */for (int I = 1; I <= 100; I ++) {System. out. println (I);} System. out. println ("Print finished ");}}

 

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.