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
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. } }
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]); } }}
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