Hand-punched notes, input and output in Java syntax, statements, and annotations.

Source: Internet
Author: User

Hand-Punched notes:

() is a note or a reminder

public static void Main (string[] args) ****** (with one method) * * * *
{
int i = 10;

int j = 20;

System.out.println (i = = j);

With and relations:

System.out.println (True & True);

System.out.println (True & false);

System.out.println (False & True);

System.out.println (False & False);


System.out.println (i >0 && j>0);

OR or relationship:


System.out.println (True | | true); (Short circuit wording, as long as the front face, it is all right) (and the opposite)

Non -:

SYSTEM.OUT.PRINTLN (! ( I < 0));

BYTE has eight bits

00000010

SYSTEM.OUT.PRINTLN (2 << 2); (00001000) Move left several depending on the latter one


3 2 = 12 3 and 2 What is the symbol equation set up

Left shift Operation Law:

X << y = x * 2 y-square


Move right to left shift opposite


Ternary operator: (cannot exist alone, assignment or output) (can be set to write)

System.out.println (i>0? "I is greater than 0": "I is less than or equal to 0"); (like if Else variant)

String str = "";

if (j>10)
{
str = "J greater than 10";
}
Else
{
str = "J not greater than 10";
}

str = J >10? "J Greater than ten": "J is not greater than 10";


System.out.println (str);


Manual input via console:

System.in input Stream

System.out output stream

Scanner SC =new Scanner (system.in); (instanced input scanner)

System.out.print ("Please enter Name:");

String Strin = Sc.nextline (); (Wait for input)

System.out.println ("The name you entered is:" + Strin); (output accepted)


Addition Calculator: (Other calculation types are optional)

System.out.print ("Please enter the first number:");

Long a =sc.nextlong ();

System.out.print ("Please enter a second number:");

Long b =sc.nextlong ();

System.out.println (A+B);


Branch statements:

int i = 10;

if (i>0)
{
SYSTEM.OUT.PRINTLN ("conditions established")
}
Else
{
SYSTEM.OUT.PRINTLN ("condition not established")
}

if (i>0) System.out.println ("i>0"); (Simplified notation)


if (i>0)
{
SYSTEM.OUT.PRINTLN ("conditions established")
}
else if (i>5)
{
SYSTEM.OUT.PRINTLN ("condition not established")
}

Else

{

}


Switch statement: (Support type: int byte char Short enumeration string)

Switch (i)

{

CASE1: (Must be constant after case)

System.out.println ("1");

Break

CASE2:

System.out.println ("4");

Break

CASE3:

System.out.println ("6");

Break

Default

System.out.println ("123");
}

Cycle:

i=10;

while (i>0)
{
System.out.println ("i =" +i);

i--;
}

Do

{
System.out.println ("i =" +i);

i--;

}

while (i>0);

for (i=0;i<10;i++)

{
System.out.println ("i =" +i);


if (i==2)
{
Continue (Skip execution later)
}

if (i==5)
{
Break
}
}

}

Hand-punched notes, input and output in Java syntax, statements, and annotations.

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.