Java Knowledge Consolidation

Source: Internet
Author: User

1. Read a character from the console:

public static void Main (String args[]) throws java.io.ioexception{

Char c= (char) System.in.read ();//read a character from the console;

Switch (c) {case ' 1 ':

System.out.println ("You are input is less than 3");

Default

System.out.println (c);

}

}

2. Break, continue, label, return control statement

(1) The loop terminates immediately when the break statement is encountered in the document Loop;

(2) The Continue statement is used to exit the current iteration of the loop without terminating the execution of the entire loop;

(3) The label label provides a way to control loops that a simple break statement cannot implement, and terminates when a break is encountered in a loop statement, regardless of other control variables. However, when you embed a condom and you want to exit the loop in a few layers of loops, you exit the loop in a normal break, and you can mark out which statement you want to exit.

eg

Char A;

outer://defines a label outer

for (int i=0;i<10:i++) {

for (int j=0;j<10;j++) {

A= (char) Systrm.in.read ();//read one character

if (a== ' B ')//If the character is B

Break outer;//Jump

if (a== ' C ')

Continue outer;

}

}

(4) return

The Ruturn statement is typically used at the end of a loop body to exit the loop and return a value. The data type of the return value must be the same as the return value type in the circular declaration.

Java Knowledge Consolidation

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.