简体   繁体   English

Java命令行参数程序

[英]Java Command Line Argument Program

My program requires input from command line arguments, it takes the integer argument and converts it to either its binary value or its decimal base 10 value. 我的程序需要从命令行参数输入,它接受整数参数并将其转换为其二进制值或十进制基数10的值。 It makes this decision by requiring the integer to have ab in front of the number for binary and ad in front for a decimal base 10. This program requires me to complete this by creating methods. 它通过要求整数在二进制数前面有a,在十进制基数10前面有ad来作出此决定。此程序要求我通过创建方法来完成此操作。 I don't know how to first check the character then to get the remaining numbers. 我不知道如何先检查字符,然后再获取剩余的数字。 I know the toBinary method but I don't know how to do the binary to decimal conversion? 我知道toBinary方法,但不知道如何将二进制转换为十进制?

use s.charAt(0) to get check first character and use 使用s.charAt(0)获取第一个字符并使用

String s1 = s.substring(1, s.length); 字符串s1 = s.substring(1,s.length);

to get remaining string number and use it to convert it to integer user Integer.parse(s1); 获取剩余的字符串号并将其转换为整数用户Integer.parse(s1); based on first character. 根据第一个字符。

use following to convert binary to integer: Integer.parseInt(s1,2) 使用以下命令将二进制转换为整数:Integer.parseInt(s1,2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM