java method从控制台获取args参数

如图1,可以直接在main中使用控制台传入的参数。现在作业要求写一个method来实现打印控制台传入的参数,不直接写在main函数里,大致是图2的结构,我毫无 头绪,应该怎么修改来实现?

翻阅古今
浏览 894回答 1
1回答

婷婷同学_

完整代码如下:123456789101112public class ArgsTest {&nbsp; &nbsp; public static void main(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; argstest(args);&nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; public static void argstest(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(args.length);&nbsp; &nbsp; &nbsp; &nbsp; for (int i = 0; i < args.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(args[i]);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java