提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
解析字符串以浮动
public class ValueOfDemo { public static void main(String[] args) { /* N o w J a v a . c o m */ // this program requires two // arguments on the command line if (args.length == 2) { // convert strings to numbers float a = (Float.valueOf(args[0])).floatValue(); float b = (Float.valueOf(args[1])).floatValue(); // do some arithmetic System.out.println("a + b = " + (a + b)); /** * 时 代 J a v a 公 众 号 - nowjava.com 提 供 **/ System.out.println("a - b = " + (a - b)); System.out.println("a * b = " + (a * b)); System.out.println("a / b = " + (a / b)); System.out.println("a % b = " + (a % b)); } else { System.out.println("This program " + "requires two command-line arguments."); } } }