Intro to Java Programming(Liang.10th)--05

5.2

5.2.5 Input and Output Redirections

input redirection

In the preceding example, if you have a large number of data to enter, it would be cumbersome
to type from the keyboard. You can store the data separated by whitespaces in a text file, say
input.txt, and run the program using the following command:

java SentinelValue < input.txt

This command is called input redirection. The program takes the input from the file input.txt rather than having the user type the data from the keyboard at runtime.

output redirection

Similarly, there is output redirection, which sends the output to a file rather than displaying it on the console. The command for output redirection is:

java ClassName > output.txt

Input and output redirection can be used in the same command. For example, the following command gets input from input.txt and sends output to output.txt:

 java SentinelValue output.txt

5.7 Minimizing Numeric Errors

Using floating-point numbers in the loop continuation condition may cause numeric errors.
Numeric errors involving floating-point numbers are inevitable, because floating-point numbers are represented in approximation in computers by nature.

not accurate

floating-point numbers 相加对精度有要求,float有时不准确,double有时也不准缺。

maybe no effect

Adding a very small number to a very big number can have no effect if the result requires more precision than the variable can store. For example, the inaccurate result of 100000000.0+ 0.000000001 is 100000000.0. To obtain more accurate results, carefully select the orderof computation. Adding smaller numbers before bigger numbers is one way to minimize errors.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值