Calculations

Java program to find quotient and remainder using method

Java program to find quotient and remainder using method

In this tutorial, we will discuss the concept of Java program to find quotient and remainder using method of two numbers When the one number divided by another

In this topic, we are going to learn how to calculate quotient and remainder of two numbers using method in Java programming language

find Quotient and Remainder

What is quotient and remainder

To find the quotient, we have used the division(/) operator. we have divided (dividend by divisor) two numbers one by another

To find remainder, we have use modular(%) operator . The dividend is divided by the divisor and the remainder is returned by the modular(%) operator

 

Java program to find quotient and remainder

Program to find quotient and remainder using method

Program 1

In this program, the user initialize two integer numbers using two variables as quotient and remainder and then the program calculates the quotient and remainder of the given numbers using method in Java language

//java program to find quotient and remainder
public class FindQuotientMethod1{
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);
//display quotient
System.out.println("remainder of "+x+" and "+y+":"+remainder);
//display remainder

}
public static void main(String args[]){//main method
int num1=400, num2=25;
//Declare and initialize variable 
quotientNum(num1,num2);//calling the method


}

}

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

Quotient of 400 and 25 is: 16
Remainder of 400 and 25 is: 0

 

 

Program to find quotient and remainder using method – entered by user

The program allows to enter two integer and then the program calculates the quotient and remainder of the given numbers  using method in Java programming language

Program 2

import java.util.Scanner;
public class FindQuotientMethod{
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);
//display quotient
System.out.println("remainder of "+x+" and "+y+":"+remainder);
//display remainder

}
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
quotientNum(num1,num2);//calling the method


}

}

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

Enter the value to num1: 123
Enter the value to num2: 12
Quotient of 123 and 12 is: 10
Remainder of 123 and 12 is: 3

 

Program to find quotient and remainder using method – with return

The program allows to enter two integer and then the program calculates the quotient and remainder of the given numbers  using method with return  in Java programming language

Program 3

import java.util.Scanner;
public class FindQuotientMethodreturn{
static int quotientNum(int x,int y){//user defind method
int quotient=x/y;//calculate quotient of two numbers
return quotient;

}
static int remainderNum(int x,int y){//user defind method
int remainder=x%y;//calculate remainder of two numbers
return remainder;

}
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));
//display quotient
System.out.println("remainder of "+num1+" and "+num2+":"+remainderNum(num1, num2));
//display remainder
;//calling the method


}

}

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

Enter the value to num1: 234
Enter the value to num2: 24
Quotient of 234 and 24 is: 9
Remainder of 234 and 24 is: 18

 

Suggested for you

Operator in Java

Data types and variable in Java

Class and main method in Java language

Method in Java language

Recursion in Java language

If statement in Java language

 

Similar post

Java code to find quotient and remainder

C code to find quotient and remainder

C++ code to find quotient and remainder

Python code to find quotient and remainder

 

C Program to Divide of two integer numbers

Java Program to Divide of two integer numbers

C++ Program to Divide of two integer numbers

Python Program to Divide of two integer numbers

 

C Program to Divide of two integer numbers using function

Java Program to Divide of two integer numbers using method

C++ Program to Divide of two integer numbers using function

Python Program to Divide of two integer numbers using function

 

C++ exercise to calculate division of two floating point numbers
Python Program to find quotient and remainder using function
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

6 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

6 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

6 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

9 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

1 year ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

1 year ago