当我运行它时,我得到了这个:
Enter 2 Integers, Do note that you will Get a Quotient and a Remainder.
Enter the First Number: 3
Now enter the Second Number: 9
Your Quotient is: 0
Your Remainder is: 3
它应该是:
Enter 2 Integers, Do note that you will Get a Quotient and a Remainder.
Enter the First Number: 3
Now enter the Second Number: 9
Your Quotient is: 3
Your Remainder is: 0
代码:
import java.util.Scanner;
public class Remainder {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int a = 0, b = 0, quotient, remainder;
int smallerNumber = 0;
int biggerNumber = 0;
System.out.println("Enter 2 Integers, Do note that you will Get a Quotient and a Remainder.");
System.out.print("Enter the First Number: ");
a = reader.nextInt();
System.out.print("Now enter the Second Number: ");
b = reader.nextInt();
remainder = (a % b);
quotient = (a / b);
remainder = (a % b);
if(a > b){
biggerNumber = a;
a = b;
}else{
smallerNumber = a;
biggerNumber = b;
}
System.out.print("Your Quotient is: ");
System.out.println(quotient);
if (remainder > 0){
System.out.print("Your Remainder is: ");
System.out.println(remainder);
}
}
}