Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C++ Program to Compute Quotient and Remainder

Java Program to Compute Quotient and Remainder

Posted on September 12, 2020May 31, 2021

Table of Contents

  • Java Program to Compute Quotient and Remainder
    • Compute Quotient and Remainder
      • Compute Quotient and Remainder-standard method
      • Compute Quotient and Remainder-using user input
      • Compute Quotient and Remainder-using method

Java Program to Compute Quotient and Remainder

In this tutorial, we will discuss the Java Program to Compute Quotient and Remainder

In this post, we are going to learn how to find quotient and remainder of two numbers using different 5 ways in Java.

Compute Quotient and Remainder

Compute Quotient and Remainder-standard method

Program 1

public class FindQuotient{

public static void main(String args[]){//main method
int num1=45,num2=4;
int quotient=num1/num2;  //  / symbol is used to calculate quotient 
int remainder=num1%num2;  // % symbol is used to calculate remainder
System.out.println("Quotient is: "+quotient);
System.out.println("remainder is: "+remainder);

}
}

When the above code is executed, it produces the following result

Quotient is: 11
remainder is: 1

 

In this program,

  • integer variables num1,num2 are declared and initialized
  • The num1 and num2 both are used to calculate quotient and remainder
  • Then,the program is displayed the quotient and remainder of using System.out.println().

 

Compute Quotient and Remainder-using user input

Program 2

import java.util.Scanner;
public class FindQuotient1{

public static void main(String args[]){//main method
Scanner scan=new Scanner(System.in);
//create a scanner instance for receives input
// from the user - input from keyboard
System.out.print("Enter the value to num1: ");
int num1=scan.nextInt();
System.out.print("Enter the value to num2: ");
int num2=scan.nextInt();
int quotient=num1/num2;  // / symbol is used to calculate quotient 
int remainder=num1%num2;  // % symbol is used to calculate remainder 
System.out.println("Quotient is: "+quotient);
System.out.println("remainder is: "+remainder);

}
}

When the above code is executed, it produces the following result

Enter the value to num1: 555
Enter the value to num1: 20
Quotient is: 27
remainder is: 15

 

  • Declare variables num1, num2
  • The program asks input from the user
  • Then the user enters the input values for num1, num2.
  • The program will read the input using scanner class and store the variables num1 and num2 respectively
  • The num1 and num2 both are used to calculate quotient and remainder
  • Then, the program displays the quotient and remainder using System.out.println() function

 

Compute Quotient and Remainder-using method

Program 3

import java.util.Scanner;
public class FindQuotient2{
static void quotientNum(int x,int y){//user defind method
int quotient=x/y;//calculate quotient of two numbers
int remainder=x%y;//calculate remainder of two numbers
System.out.println("Quotient of "+x+" and "+y+":"+quotient);
System.out.println("remainder of "+x+" and "+y+":"+remainder);
//display result

}
public static void main(String args[]){//main method
Scanner scan=new Scanner(System.in);
//create a scanner instance for receives input
// from the user - input from keyboard
System.out.print("Enter the value to num1: ");
int num1=scan.nextInt();
System.out.print("Enter the value to num2: ");
int num2=scan.nextInt();
quotientNum(num1,num2);//calling the method


}

}

When the above code is executed, it produces the following result

Enter the value to num1: 345
Enter the value to num1: 20
Quotient of 345 and 20: 17
remainder of 345 and 20: 5


In the program,

  • Declare variables num1, num2.
  • The program asks input from the user
  • Then the user enters the input values for num1, num2.
  • The program will read the input using scanner class and store the variables num1 and num2 respectively
  • Define the method(quotientNum()) to calculate division of given two numbers
  • Call the method to produce output
  • finally, the program displays quotient and remainder using System.out.println()

 

Program 4

import java.util.Scanner;
public class FindQuotientMethodreturn{
static int quotientNum(int x,int y){//user defind method for find quotient
int quotient=x/y;//caculate quotient of two numbers
return quotient;
//Using return keyword to return result to main method
}
static int remainderNum(int x,int y){//user defind method for find remainder
int remainder=x%y;//caculate remainder of two numbers
return remainder;
//Using return keyword to return result to main method
}
public static void main(String args[]){//main method
Scanner scan=new Scanner(System.in);
//create a scanner instance for receives input
// from the user - input from keyboard
System.out.print("Enter the value to num1: ");
int num1=scan.nextInt();
//reading the user input for num1
System.out.print("Enter the value to num2: ");
int num2=scan.nextInt();
//reading the user input for num2
System.out.println("Quotient of "+num1+" and "+num2+":"+quotientNum(num1,num2));
//calling the method to display quotient
System.out.println("remainder of "+num1+" and "+num2+":"+remainderNum(num1, num2));
//calling the method to display remainder


}

}

 

Enter the integer value to num1: 56

Enter the integer value to num2: 5

Quotient of 56 and 5 is: 11

Remainder of 56 and 5 is: 1

 

 

Suggested post

Data type and variable in Java language

variable types in Java language

Operator in Java language

if statement in Java language

For loop in Java language

Method in Java language

Recursion in Java language

 

Similar post

Python Program to Compute Quotient and Remainder

C++ Program to Compute Quotient and Remainder

C Program to Compute Quotient and Remainder

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes