Exception handling
Try{}Catch(Exception e) {}voidWork ()throwsException {}//Throw ExceptionThrow NewException ("the character entered cannot be empty!") "); classMyException1extendsException {//Custom Exception ClassesString msg =NULL; PublicMyException1 (String m) { This. msg =m; } PublicString toString () {return"Throw a Custom exception:" +msg; }} Public classTest { Public Static voidMain (string[] args) {inti = 10; Try{ if(I < 100) { Throw NewMyException1 ("Input value less than 100");//Throw Exception } } Catch(MyException1 ex) {System.out.println (ex); //The ex.tostring () method is called } }}
Input stream
import Java.util.Scanner; // Include this package Scanner in=New// New Stream object int a=in.nextint (); // Enter int type double d=in.nextdouble (); // Enter double type // Input String
Output
// output with wrapped lines System.out.println (a); // can output various types of data such as int System.out.printf ("%d\n", a); // a format similar to the C language // similar to cout // control the output of the format
Type conversions
String str= "abc"char[] C=str.tochararray (); // convert String to char[] Char [] c={' A ', ' B ', ' C '}; String str=new string (c); // char[] Convert to String String s= ""; int // convert string to int Double // convert string to double
Math.Abs (); // The absolute value function, a lot of math functions have to add math. To invoke
// control format converts numbers directly to strings
String[] Sub=s.split ("|\n"); // separates a string with some separators
Open array
Double [] a=newdouble// two-dimensional double int[] b=newint// int type string[] s=new//String int// more than a multi-dimensional c like a few []
Basic Java Knowledge