import java.util.Scanner;
public class suanshu {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("输入第一个数字: ");
int num1 = sc.nextInt();
System.out.print("输入第二个数字: ");
int num2 = sc.nextInt();
// 加法
int sum = num1 + num2;
System.out.println("和为: " + sum);
// 减法
int difference = num1 - num2;
System.out.println("差为: " + difference);
// 乘法
if(num1 == 0 || num2 == 0) {
System.out.println("两个数不能有0");
} else {
int product = num1 * num2;
System.out.println("积为: " + product);
}
// 除法
if(num1 ==0||num2 == 0) {
System.out.println("两个数不能有0");
} else {
int quotient = num1 / num2;
System.out.println("商为: " + quotient);
}
}
}
Java实现加减乘除
最新推荐文章于 2024-01-01 11:23:34 发布