나는 지난 2 시간 정도이 문제를 해결하기 위해 노력해 왔으며로드 블록을 만났습니다. 나는 실제로 나누기를 수행 할 수 있지만 0이 아닌 나머지를 인쇄 할 때 출력이 일치하지 않습니다. 나는 내가 뭘 잘못하고 있는지 알고 싶다.나눗셈 및 모듈러스 연산자가없는 나머지 및 나머지
public class Division {
public static void main(String[] args) {
int numerator = 0;
int numeratorprint = 0;
int denominator = 0;
int product = 0;
int remainder = 0;
int counter = 1;
Scanner input;
input = new Scanner(System.in);
System.out.print("Enter two positive intergers for division:\n");
numerator = input.nextInt();
numeratorprint = numerator;
denominator = input.nextInt();
while ((numerator < 0) || (denominator < 0)) {
System.out.print("Enter two positive intergers for division:\n");
numerator = input.nextInt();
denominator = input.nextInt();
}
if (numerator == 0){
System.out.print(numerator + "/" + denominator + " = " + numerator + " with a remainder of " + numerator);
}
else if (denominator == 0){
System.out.print("This result is undefined (Cannot divide by Zero)");
}
else if (denominator > numerator){
System.out.print("Cannot do proper fractions");
}
else {
while (numerator > denominator){
counter++;
numerator = numerator - denominator;
}
}
product = counter * denominator;
remainder = numeratorprint - product;
System.out.println(numeratorprint + "/" + denominator + " = " + counter + " with a remainder of " + remainder);
}
}
/* Sample I/O 1
Enter two positive intergers for division:
25
5
OUTPUT:
25/5 = 5 with a remainder of 0
Sample I/O 2
Enter two positive intergers for division:
27
5
OUTPUT:
27/5 = 6 with a remainder of -3
*/
주를 제거 할 수 있습니다 분자가 적당한 비율 때입니다 분모보다 작은 경우 그. 부적절한 분수는 그 반대의 경우입니다. – HyperNeutrino
감사합니다., 정정 해주십시오. – malmonte