Basic syntax for Java

Source: Internet
Author: User

One: Data type

Base type, string type, and null type can specify a direct amount

Two: Conditional statements

If

If-else

Switch

No matches, execution by item

 PackageOne ; Public classSWITCHS1 { Public Static voidMain (string[] args) {intx= 0; Switch(x) {default: System.out.println ("Default");  Case1: System.out.println (1);  Case2: System.out.println (2); }    }}

Start execution from a match

 PackageOne ; Public classSWITCHS2 { Public Static voidMain (string[] args) {intx= 0; Switch(x) {default: System.out.println ("Default");  Case0: System.out.println (0);  Case1: System.out.println (1);  Case2: System.out.println (2); }    }}

 PackageOne ; Public classSWITCHS2 { Public Static voidMain (string[] args) {intx= 0; Switch(x) { Case0: System.out.println (0);  Case1: System.out.println (1);  Case2: System.out.println (2); default: System.out.println ("Default"); }    }}

Three: Circular statements

For

While

Do-while

 PackageOne ; Public classXunhuan { Public Static voidMain (string[] args) { for(intA = 0; A < 10; a++) {System.out.print (a);                } System.out.println (); intx = 0;  while(X < 20) {System.out.print (x); X++;                } System.out.println (); inty = 0;  Do{System.out.print (y); Y++; } while(Y < 10); }}

Four: Jump statements

Break (jump out of the loop)

Continue (enter next cycle)

 Package One ;  Public class Tiaozhuan {    publicstaticvoid  main (string[] args) {        for (int a = 0; a <; a++) {            System.out.print (a);             if (a% 2 = = 0)                {continue;            }            System.out.println ("$");     }}}

Basic syntax for Java

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.