public void showSumAndSub(int ipar1,int ipar2){
System.out.println("两个数的和为:"+ipar1+ipar2);
System.out.println("两个数的差为:"+ipar1-ipar2);
}
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = 0;
int b = 0;
try{
System.out.println("请输入a的值:");
a = Integer.parseInt(sc.nextLine());
System.out.println("请输入b的值:");
b = Integer.parseInt(sc.nextLine());
System.out.println("a+b="+(a+b));
System.out.println("a-b="+(a-b));
}catch(Exception e){
System.out.println("你输入的不全是数字!");}}
}
希望你喜欢。
public class test {
public static void main(String[] args){
int a=0;
int b=0;
if(args.length < 2) {
System.out.println("usage: test int1 int2");
return;
}
try{
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[1]);
}
catch(Exception e){
System.out.println("please follow the usage: java test int1 int2");
return;
}
System.out.println("a + b = "+(a+b));
System.out.println("a - b = "+(a-b));
}
}