10_9 Java Notes

Source: Internet
Author: User

All the keywords in Java are lowercase
Note that while main is recognized by the compiler, it is not a keyword
Package: (lowercase name)
Single-stage package: Liyi
Multi-level package: Cn.itcast

The difference between path and classpath:
An executable file, such as an. exe file, is logged in the PATH environment variable, and for an executable file now
Go down the front path, and if you don't find it, you can find the path configured in the PATH environment variable.

The directory where the Java class's running files are located is recorded in the CLASSPATH environment variable. For class files,
First find the path under Classpath, and then find the current path

Be sure to develop the habit of writing the code before writing it.

The thought through the annotation first to organize out, then uses the code to realize because the code is only one embodiment form of the thought!!!

Note In addition to explaining the program, but also to help us debug the program, 1.1-point debugging
The following is the output of different types of data, including the output of several binary numbers

 Public classDemo { Public Static voidMain (string[] args) {//output of string constantsSystem.out.println ("Hello"); //output of Integer constants (decimal)SYSTEM.OUT.PRINTLN (100);//Output//output of Integer constants (binary)System.out.println (0b100);//Output 4//output of Integer constants (octal)System.out.println (0100);//Output//output of integer constant (hex)System.out.println (0x100);//Output//output of decimal constantsSystem.out.println (10.123); //output of character constantsSystem.out.println (' 0 '); //output of Boolean constantsSystem.out.println (true); }}

The random method in Java.lang.Math returns a Doble (excluding 1.0) between a 0-1.0.
Examples of Use methods:
int magic = (int) (Math.random () *101) +100;
This method *101 get the random number between 1--100, plus 100 to get the random number between 100--200

 Packagedemo;ImportJava.util.Scanner; Public classdemo{ Public Static voidMain (string[] args) {intMagic =(int) (Math.random () *101) +100; Scanner SC=NewScanner (system.in); System.out.println ("Please enter the number you guessed"); intGuess =Sc.nextint ();  while(Guess! =Magic) {            if(Guess >Magic) {System.out.println ("Error, the number is too large, please re-guess"); }Else{System.out.println ("Error, the number is too small, please re-guess"); } Guess=Sc.nextint (); } System.out.println ("Congratulations, right, the number is" +Magic); }}

String converted to lowercase

 Packagedemo;ImportJava.util.Scanner;/*string converted to lowercase*//*where toLowerCase's role is to convert a string to a lowercase string*/ Public classDemo { Public Static voidMain (string[] args) {String month= ""; intMonthNumber = 0; Scanner input=NewScanner (system.in); System.out.print ("Please enter the month:"); Month=Input.next (); Switch(month.tolowercase()) { Case"January": MonthNumber = 1; Break;  Case"February": MonthNumber = 2; Break;  Case"March": MonthNumber = 3; Break;  Case"April": MonthNumber = 4; Break;  Case"May": MonthNumber = 5; Break;  Case"June": MonthNumber = 6; Break;  Case"July": MonthNumber = 7; Break;  Case"August": MonthNumber = 8; Break;  Case"September": MonthNumber = 9; Break;  Case"October": MonthNumber = 10; Break;  Case"November": MonthNumber = 11; Break;  Case"December": MonthNumber = 12; Break; default: monthnumber = 0; Break; }        if(MonthNumber = = 0) {System.out.println ("The entered month is illegal!" "); }Else{System.out.println (month+ "is" +monthnumber+ "month"); }    }}

Use of a tagged break
Here, the label start is used to identify the outer for loop, so the break start here jumps out of the outer loop

 Packagedemo; Public classDemo { Public Static voidMain (string[] args) { start: for(inti = 0; I < 3; i++){                 for(intj = 0; J < 4; J + +){                    if(J = = 2){                         Break start; } System.out.println (I+":"+j); }            }    }}

Similarly, tagged continue;

 public  class   Demo { public  static  void   main (string[] args) {start:  for  (int  i = 0; i < 3; i++< Span style= "color: #000000;" ) { for  (int  j = 0; J < 4; J++ if  (j = = 2)  continue   start;                System.out.println (i  + ":" +j); }            }    }}

This sentence is not quite understand now:
  A tagged break can be used for looping structures and tagged statement blocks, while tagged continue can only be used for loop structures.

Integrated use of tagged continue and break;

 Packagedemo; Public classDemo { Public Static voidMain (string[] args) {outer: for(inti = 0; I < 3; i++) {System.out.println ("I =" +i); Inner: for(intj = 0; J < 100; J + +){                        if(j = = 20)                             Breakouter; if(j% 3 = = 0)                            Continueinner; System.out.println ("J =" +j); } System.out.println ("This won't be print.");        } System.out.println (); System.out.println (1); }}

You can use a goto statement to jump from an inner loop to an outer loop in the C + + language, but it doesn't make sense to use Goto as a keyword in the Java language.



10_9 Java Notes

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.