我该如何做到这一点,当 Wholenumber2 = 0 时,它会显示不同的消息,然后如果 Wholenumber 是 < 或 > 但不是 = 0,它将显示另一条消息?我试图防止潜水0的基本错误。
package SumDifProPACKAGE; // Assigns package code.
import java.util.Scanner; // Program uses class Scanner.
public class SumDifProCLASS { // Public class.
public static void main( String[] args ){
// Displays Welcome, information on calculations & creators name.
System.out.printf( "%s\n%s\n%s\n",
"--Welcome to JAVA Calculator!--", " --Sum, Difference, Product--", " --??--");
// Creates a Scanner to obtain input from the command window.
Scanner input = new Scanner( System.in );
// Listed integers:
int wholenumber1; // First whole number input.
int wholenumber2; // Second whole number input.
int sum; // Sum of First & Second whole number input.
int difference; // Difference of First & Second whole number input.
int product; // Product of First & Second whole number input.
int quotient; // Quotient of First & Second whole number input.
int remainder; // Remainder of the Quotient.
int zero = 0;
// Requests input for First whole number.
System.out.print( "Please enter first whole number..." );
wholenumber1 = input.nextInt();
// Requests input for Second whole number.
System.out.print( "Please enter first whole number..." );
wholenumber2 = input.nextInt();
// Displays the sum of First & Second input.
sum = wholenumber1 + wholenumber2;
System.out.printf( "Sum = %d\n", sum);
// Displays the difference of First & Second input.
difference = wholenumber1 - wholenumber2;
System.out.printf( "Difference = %d\n", difference);
// Displays the product of the First & Second input.
product = wholenumber1 * wholenumber2;
System.out.printf( "Product = %d\n", product);
// Displays the quotient without the remainder of the First & Second input.
quotient = wholenumber1 / wholenumber2;
System.out.printf( "Quotient = %d", quotient);
// Displays the remainder, continuation of quotient.
remainder = wholenumber1 % wholenumber2;
System.out.printf( "r%d\n", remainder);
}