Algorithms - Java中"stdlib"的使用

Java中"stdlib"的使用

 

本文地址: http://blog.csdn.net/caroline_wendy/article/details/17057265

 

stdlibjava中的输入输出库, 网址: http://introcs.cs.princeton.edu/java/stdlib

CSDN下载地址: http://download.csdn.net/detail/u012515223/6639631

stdlib.jar放入Eclipse的dropins文件夹内,加载stdlib.jar, 位置: 项目->Properties, 如图:

stdlib主要包含两组函数: In & Out, StdIn & StdOut

In & Out 是通过参数进行读取; StdIn & StdOut 是直接通过Console进行读取;

具体代码如下:

 

public class Stdlib
{	
	public static void main(String args[])
	{
		//In&Out的用法
		Out out = new Out(System.out);
		out.println("Read a file of integers: ");
		In in = new In(args[0]);
		int arr[] = in.readAllInts();
		for (int i : arr) { out.print(i + " "); }
		out.println("end");
		
		//StdIn&StdOut的用法
		StdOut.println("Please input an array of integers (Ctrl+Z end): ");
		while(!StdIn.isEmpty()) {
			int val = StdIn.readInt();
			StdOut.print(val + " ");
		}
		StdOut.println("end");
	}
}


输出:

 

 

Read a file of integers: 
1 2 3 4 5 6 7 8 9 10 end
Please input an array of integers (Ctrl+Z end): 
11 12 13 14 15
11 12 13 14 15 end

 

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ElminsterAumar

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值