[复习]Java输入输出与数组

很久没用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数组的使用

http://blog.csdn.net/e421083458/article/details/8146236

//静态数组
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};
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值