Trigonometric Methods
Math.sin (radians): Math.sin (MATH.PI/6) =0.5
Math.Cos (radians): Math.Cos (MATH.PI/3) =0.5
Math.tan (radians): Math.tan (MATH.PI/3) =1.732
Math.toradians (degrees): Math.toradians (+) =math.pi/6=0.5236
Math.todegrees (radians): Math.todegrees (MATH.PI/2) =90.0
Math.asin (a): Math.asin (0.5) =math.pi/6=0.52359877
Math.acos (a): Math.acos (0.5) =math.pi/3=1.0471975511965979
Math.atan (a): Math.atan (1.0) =math.pi/4=0.7853981633974483
exponential function Method
Math.exp (1) =math.e=2.718281828459045
Math.log (MATH.E) =1.0
MATH.LOG10 (10) =1.0
Math.pow (2,3) =8.0
MATH.SQRT (4) =2.0
Rounding Function Method
Math.ceil (x): Math.ceil (4.4) =5.0 or Math.ceil (4.6) =5.0
Math.floor (x): Math.floor (4.4) =4.0 or Math.floor (4.6) =4.0
Math.Round (x): rounded that is math.round (4.4) =4 or Math.Round (4.6) =5
Math.rint (x): Returns the nearest integer if the distance is equal to the nearest even number. Math.rint (4.4) =4.0 or math. (4.5) =4.0 (even) or Math.rint (4.6) =5.0
min, Max and ABS methods
Math.min (2,4) return 2,math.min (2,4.0) return 2.0
Math.max (2,3) return 3,math.max (2.0,3) return 3.0
Math.Abs (-2) return 2,math.abs (-2.0) return 2.0
Random Method
0.0<=math.random () <1.0
(int) (Math.random () *10) returns a random integer between 0~9
50+ (int) (Math.random () *50) returns a random integer between 50~99
50.0<=50+math.random () *50<100
Character class method
Character.isdigit (' 0~9 ') returns Ture,character.isdigit (' a ') returns false or Charcter.isdigit (' a ') returns false
Character.isletter (' a ') returns True,character.isletter (' a ') return True,character.isletter (' 9 ') returns false
Character.isletterordigit (' a ') returns True,character.isletterordigit (' a ') returns True,character.isletterordigit (' 0~9 ') Returns True
Character.islowercase (' a ') returns True,character.islowercase (' a ') return False,character.islowercase (' 8 ') returns false
Character.isuppercase (' a ') returns True,character.isuppercase (' a ') return False,character.isuppercase (' 8 ') returns false
Character.tolowercase (' a ') returns A,character.tolowercase (' a ') returns A,character.tolowercase (' 8 ') return 8
Character.touppercase (' a ') returns A,character.touppercase (' a ') return A,character.touppercase (' @ ') return @
simple methods for string objects
"String". Length () returns the number of characters in a string
"String". CharAt (index) returns the character at the specified position in the string (index starts at 0)
"String A". Concat ("string B") returns "string a string B"
"String". toLowerCase () returns "String lowercase"
"String". toUpperCase () returns "String uppercase"
"String". Trim () Returns a new "string" that removes whitespace characters from both sides, including whitespace, \ t, \f, \ r, \ n
System.out.println ("Good Good study,
Day up! "); Statement error, string constants cannot be serialized, serial must be added ' + '
comparison method for string objects
"A". Equals ("a") returns True, "a". Equals ("B") returns false
"A". Equalsignorecase ("a") returns True, "a". Equalsignorecase ("B") returns false
"A". CompareTo ("B") returns 1, "B". CompareTo ("A") returns 1, "a". CompareTo ("a") returns 0, "a". CompareTo ("a") returns-32
"A". Comparetoignorecase ("a") returns 0, "a". Comparetoignorecase ("B") returns-1, "B". CompareTo ("A") returns 1
"AB". StartsWith ("A") returns True, "AB". StartsWith ("") returns True, "AB". StartsWith ("B") returns false, "AB". StartsWith ("AB") returns false
"AB". EndsWith ("B") returns True, "AB". EndsWith ("") returns True, "AB". EndsWith ("A") returns false, "AB". EndsWith ("AB") returns false
"ABC". CONTAINS ("AB") returns True, "ABC". CONTAINS ("BC") returns True, "ABC". CONTAINS ("AC") returns FALSE, "ABC". CONTAINS ("") returns True
methods for string objects to get substrings
"ABCD efgh ijkl". Substring (5) return to "Efgh IJKL"
"ABCD efgh ijkl". substring (5,9) return "EFGH"
String object method that gets the index value of the character in the string
INDEXOF (CH): Returns the subscript of the first ch that appears in a string, if not, returns 1
IndexOf (Ch,fromindex): Returns the subscript of the first CH that appears after the string fromIndex, if not, returns 1
IndexOf (s): Returns the subscript of the first string s that appears in the string, or 1 if not
IndexOf (S,fromindex): Returns the subscript of the first string s that appears after fromIndex in a string, if not, returns 1
LASTINDEXOF (CH): Returns the subscript of the last ch that appears in the string, if not, returns 1
LastIndexOf (Ch,fromindex): Returns the subscript of the last ch that occurred before the string fromIndex, if not, returns-1
LastIndexOf (s): Returns the subscript of the last string that appears in the string, if not, returns 1
LastIndexOf (S,fromindex): Returns the subscript of the last string s that appears before fromIndex in the string, if not, returns 1
Suppose a string s contains a first and last name separated by a space, and the following code can be used to extract the first and last names:
int k = S.indexof ("");
String firstName = s.substring (0,k);
String lastName = s.substring (k+1);
the conversion between a string and a number
int intvalue = Integer.parseint ("123");
D ouble doublevalue = double.parsedouble ("123.456");
String s = 123+ ""; System.out.println (s); the output is a string 123
System.out.println ("Welcome" + (' \u0001 ' + 1)) outputs the result of Welcome 2
System.out.println ("Welcome" +1+1) outputs the result of Welcome 11
System.out.println ("Welcome" + ' a ' + 1) outputs a result of Welcome A1
System.out.println (' A ' +1+ "Welcome") outputs the result of 98 Welcome
methods for scanner objects
Java.util.Scanner input = new Java.util.Scanner (system.in);
Input.next () reads the string ending with a white space character (' ', ' \ t ', ' \f ', ' \ n ', ' \ R ')
Input.nextline () reads a string that presses the ENTER key to the end flag
For example:
Java.util.Scanner input = new Java.util.Scanner (system.in);
System.out.print ("Enter three words separated by spaces:");
String S1 = Input.next ();
String s2 = Input.next ();
String s3 = Input.next ();
System.out.println (S1);
SYSTEM.OUT.PRINTLN (S2);
System.out.println (S3);
Displays:
Enter three words separated by Spaces:welcome to Java
Welcome
To
Java
For example:
Java.util.Scanner input = new Java.util.Scanner (system.in);
System.out.print ("Enter a Line:");
String s = input.nextline ();
SYSTEM.OUT.PRINTLN ("The line entered is" +s);
Displays:
Enter a line:welcome to Java
The line entered are Welcome to Java
To avoid input errors, do not use Nextfloat () after Nextbyte (), Nextshort, Nextint (), Nextlong (), nextdouble (), nextline (), and Next ()
Java Learning Summary II