java identifiers; constants; arrays

Source: Internet
Author: User

    • Identifier

Specification for custom identifiers:

1. the first letter of the class name and interface list Word is capitalized, and the other words are lowercase.   For example: class RunTime. Interface A

2. variable name and method (function) The first word is all lowercase, other words are capitalized in the first letter, and other lowercase. For example: docook ();

3. package name all words lowercase.

4. constant All the words are capitalized, and the words are separated from the words using an underscore. For example: up_direction

    • Constant

Categories of constants:

Integer constant 10 12

Decimal constant 3.14

Boolean Constants A Boolean constant has only two values: true ( correct ). False ( error )

Character Constants a character constant is a single character that is enclosed in single quotation marks, which we call the character constant.

string Yield A string constant is a literal string constant that is referred to as a word using double quotation marks.

    • Steps to accept keyboard input data:

1. create a Scanner object.

2. call the Nextint method of the scanner object to scan the data.

3. Import the package.

 ImportJava.util.*; classDemo3 { Public Static voidMain (string[] args) {//Create a scannerScanner Scanner =NewScanner (system.in); //call scanner to scan keyboard input dataSystem.out.println ("Please enter a score:"); intScore = Scanner.nextint ();//defines a num variable to receive a scan to the content.      } }

    • Array

classDemo4 { Public Static voidMain (string[] args) {//define an array        int[] arr =New int[4]; arr[0] = 10; arr[1] = 30; arr[2] = 50; arr[3] = 90; //System.out.println ("Capacity of the array:" + arr.length); //The array has a length property that can be used to view the capacity of the array. //System.out.println ("arr[2] =" + arr[2]); //View all the data in the array.          for(intindex = 0; Index<arr.length; index++) {System.out.println (Arr[index]); }    }}

    • Array sorting
ImportJava.util.*;classDemo14 { Public Static voidMain (string[] args) {int[] arr = {12,3,1,10,8}; //method of sortingArrays.sort (arr); String Info=arrays.tostring (arr); System.out.println ("Elements of the array:" +info); //1, 3, 8, ten,        intindex = Arrays.binarysearch (arr,9);//Binary Lookup: If the corresponding element can be found in the array, then the index value of the data is returned, and if not found then a negative number is returned. System.out.println ("Index value found:" +index); }}

java identifiers; constants; arrays

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.