当前位置: 技术问答>java相关
请给个命令行输入的例子!
来源: 互联网 发布时间:2015-04-05
本文导语: 解题,由命令行输入3个数,求和! | 小错误: ...... if (args.length == 3){ //应该是等于3才往下走 System.out.println("usage: ArgsIn x y z"); int x = Integer.parseInt(args[0]); int y = Integer.parseInt(args[1]...
解题,由命令行输入3个数,求和!
|
小错误:
......
if (args.length == 3){
//应该是等于3才往下走
System.out.println("usage: ArgsIn x y z");
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
System.out.println(x+y+z);
}
....
......
if (args.length == 3){
//应该是等于3才往下走
System.out.println("usage: ArgsIn x y z");
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
System.out.println(x+y+z);
}
....
|
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while (true)
{
System.out.print("Please input 3 numbers: ");
try
{
String num1 = in.readLine();
int number1=Integer.parseInt(num1);
String num2 = in.readLine();
int number2=Integer.parseInt(num2);
String num3 = in.readLine();
int number3=Integer.parseInt(num3);
System.out.println(number1+number2+number3);
if (line.equals("N")||line.equals("n"))
{
break;
}
catch(Exception e)
{
System.out.println(e);
}
}
while (true)
{
System.out.print("Please input 3 numbers: ");
try
{
String num1 = in.readLine();
int number1=Integer.parseInt(num1);
String num2 = in.readLine();
int number2=Integer.parseInt(num2);
String num3 = in.readLine();
int number3=Integer.parseInt(num3);
System.out.println(number1+number2+number3);
if (line.equals("N")||line.equals("n"))
{
break;
}
catch(Exception e)
{
System.out.println(e);
}
}
|
import java.io.*;
public class LineIn{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input 3 number>");
String line = in.readLine();
int x = Integer.parseInt(line);
line = in.readLine();
int y = Integer.parseInt(line);
line = in.readLine();
int z = Integer.parseInt(line);
System.out.println(x+y+z);
}
}
public class LineIn{
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("input 3 number>");
String line = in.readLine();
int x = Integer.parseInt(line);
line = in.readLine();
int y = Integer.parseInt(line);
line = in.readLine();
int z = Integer.parseInt(line);
System.out.println(x+y+z);
}
}
|
public class ArgsIn{
public static void main(String[] args){
if (args.length != 3)
System.out.println("usage: ArgsIn x y z");
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
System.out.println(x+y+z);
}
}
public static void main(String[] args){
if (args.length != 3)
System.out.println("usage: ArgsIn x y z");
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
int z = Integer.parseInt(args[2]);
System.out.println(x+y+z);
}
}