很久没用Java写过命令行了……感觉Java基础都忘干净了。
略微复习一下:
Java输入输出
1.使用BufferedReader方法输入:
public static String readLine() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
}
2.直接使用System.in输入:
public static String readLine() thorws IOException{
byte b[] = new byte[1024];
int i = System.in.read(b);
return new String(b, 0, i-2);
}
3.使用Scanner输入(推荐):
public static String readLine()
{
Scanner s = new Scanner(System.in);
return s.nextLine(); //s.nextInt();
}
Java数组的使用
//静态数组
public class Test {
public static void main(String[] args) {
int score[]=null;//声明数组
score=new int[3];//开辟空间,大小为3
}
}
//多维数组与一维数组差不多
int[][] a = new int[1001][1001];
//动态数组
ArrayList list = new ArrayList();
int[] a = new int[5];
for (int i=0;i<a.length;i++)
System.out.println(a[i]);
//输出为五个0
//从这里看出来,在初始化的时候会给a数组每个元素赋值为0
//---在C/C++中则可以直接写int a[5] = {0};