Java基础知识
异常处理
try {}
catch(Exception e) {}
void work() throws Exception {}
throw new Exception("输入的字符不能为空!");
class MyException1 extends Exception
{String msg = null;public MyException1(String m){this.msg = m;}public String toString(){return "抛出自定义异常:" + msg;}
}
public class test
{public static void main(String[] args){int i = 10;try{if (i < 100){throw new MyException1("输入值小于100"); }}catch (MyException1 ex){System.out.println(ex); }}
}
输入流
import java.util.Scanner;
Scanner in=new Scanner(System.in);
int a=in.nextInt();
double d=in.nextDouble();
String s=in.nextLine();
输出
System.out.println("输入有误");
System.out.println(a);
System.out.printf("%d\n",a);
System.out.print(P[i].id+" "+P[i].name+" "+P[i].age+"\n");
System.out.print(String.format("%4d\n",c));
Math.abs();
String ans=String.format("%.6f", T2);
String[] sub=s.split(" |\n");
类型转换
String str="abc";char[ ] c=str.toCharArray();
char[ ] c={'a','b','c'};String str=new String(c);
String s="34";
int Age=Integer.parseInt(s);
double e=Double.parseDouble(es);
开数组
double[][] A=new double[N+1][N+1];
int[] B=new int[N];
String[] S=new String[N];
int C[100];
多维就多加几个[]