double A = Integer.parseInt(args[0])

Integer.parseInt(args[0])中,Integer是java中的一个内置类,parseInt()是这个类的一个静态方法,这个方法的作用是把括号里面的参数(args[0])转为int型的值

但是Integer.parseInt(args[0])要怎么用?

题目
在这里插入图片描述

这样直接运行会报错
要先往命令行输入才能运行

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package transpotion; import java.lang.reflect.InvocationTargetException; public class ComputeTime { public static void main(String[] args) { System.out.println("Mode of transportation is:"+args[0]); System.out.println("A="+args[1]); System.out.println("B="+args[2]); System.out.println("C="+args[3]); double a=Double.parseDouble(args[1]); double b=Double.parseDouble(args[2]); double c=Double.parseDouble(args[3]); double v,t; try { Common d=(Common) Class.forName("transpotion." +args[0]).getDeclaredConstructor().newInstance(); v=d.speed(a,b,c); t=1000/v; System.out.println("速度=:"+v+"km/h"); System.out.println("时间=:"+(float)t+"h"); } catch(ClassNotFoundException| InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { System.out.println("class not found"); } } } package transpotion; public interface Common { double speed(double a,double b,double c); } package transpotion; public class Car007 implements Common{ public double speed(double a, double b, double c) { if(c==0) { System.out.println("Divisor cannot be 0"); return 0; } else return ab/c; } } package transpotion; public class Plane implements Common { public double speed(double a, double b, double c) { return a+b+c; } } package transpotion; public class Ship implements Common { public double speed(double a,double b,double c) { return ab+a*c; } }可以为我讲解一下这段代码中的String tools = args[0]; int a = Integer.parseInt(args[1]); int b = Integer.parseInt(args[2]); int c = Integer.parseInt(args[3]); Common d = (Common) Class.forName("LAB2." + tools).newInstance(); float time = d.time(a, b, c); System.out.println(time);这部分吗,最好详细点
最新发布
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值