In this program, you’ll learn to compute quotient and remainder from the given dividend and divisor in Java
Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package javaexamples; import java.util.Scanner; public class JavaExamples { public static void main(String[] args) { int dividend = 450, divisor = 8; int quotient = dividend / divisor; int remainder = dividend % divisor; String output1 = String.format("dividend:%d \ndivisor:%d",dividend,divisor); String output2 = String.format("Quotient = %d \nRemainder =%d ",quotient,remainder); System.out.println(output1); System.out.println(output2); } } |
Output:
Java Code: Entered by User
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | package javaexamples; import java.util.Scanner; public class JavaExamples { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Enter First Number: "); int dividend = reader.nextInt(); System.out.print("Enter Second Number: "); int divisor = reader.nextInt(); int quotient = dividend / divisor; int remainder = dividend % divisor; String output1 = String.format("dividend:%d \ndivisor:%d",dividend,divisor); String output2 = String.format("Quotient = %d \nRemainder =%d ",quotient,remainder); System.out.println(output1); System.out.println(output2); } } |
Output: