编写一个程序从标准输入终端上两个大于0的整数a和b,计算a处以b得到c,并将结果保留两位小数打印在标准输出设备上。
1
2
3
4
5
|
input a:
10
input b:
1
c=10.00
|
1
2
3
|
input a:
abc
Error Input
|
1
2
3
4
5
|
input a:
10
input b:
abc
Error Input
|
1
2
3
4
5
|
input a:
10
input b:
0
Inf
|
注意:
- 最后没有换行。
- "input a:" 和 “input b:”后各有一个换行
- 输入内容后存在一个换行
import java.util.Scanner;
import java.text.DecimalFormat;
public class T001_UT001_0006
{
public static void main(String[] agrs)
{
Scanner njp_input=new Scanner(System.in);
double njp_a,njp_b,njp_c;
try
{
System.out.println("input a:");
njp_a=njp_input.nextInt();
System.out.println("input b:");
njp_b=njp_input.nextInt();
if(njp_b==0)
System.out.print("Inf");
else
{
njp_c=(float)njp_a/njp_b;
DecimalFormat njp_df=new DecimalFormat("0.00");
String njp_s=njp_df.format(njp_c);
System.out.print("c="+njp_s);
}
}
catch(Exception e){System.out.print("Error Input");}
}
}