作业帮 > 综合 > 作业

编写一个java应用程序,要求输入两个整数,并显示这两个数的和、差.

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/11 17:26:51
编写一个java应用程序,要求输入两个整数,并显示这两个数的和、差.
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("你输入的不全是数字!");}}
}
希望你喜欢.