Find quotient and remainder in java | codeYourslf ๐Ÿ‘จ‍๐Ÿ’ป

Find quotient and remainder in java programming, java basic questions for beginners, java for beginners, codeYourslf- coding on mobile
Find quotient and remainder in java | codeYourslf ๐Ÿ‘จ‍๐Ÿ’ป

Source code of this problem statement :

// Find the quotient and reminder of a number

package asicQuestion;

import java.util.Scanner;

public class quotientAndReminder {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    System.out.println("Enter dividend value");

    int dividend = sc.nextInt();

    System.out.println("Enter divisor value");

    int divisor = sc.nextInt();

    float quotient;

    int reminder;

    quotient = dividend / divisor;

    reminder = dividend % divisor;

    System.out.println("The value of quotient is: " + quotient);

    System.out.println("The value of reminder is: " + reminder);

  }

}




 

Source code for " find quotient and remainder in java"  with exception handling :

Why should we use exception handling, see if the user enters value 10 and 0 here 10/0 is not possible, so we have to handle that case manually by using exception handling.
// Find the quotient and reminder of a number

package asicQuestion;

import java.util.Scanner;

public class quotientAndReminder {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    System.out.println("Enter dividend value");

    int dividend = sc.nextInt();

    System.out.println("Enter divisor value");

    int divisor = sc.nextInt();

    float quotient;

    int reminder;

    try {

      quotient = dividend / divisor;

      reminder = dividend % divisor;

      System.out.println("The value of quotient is: " + quotient);

      System.out.println("The value of reminder is: " + reminder);

    } catch (Exception e) {

      System.out.println("The error is: " + e);

    }

  }

}

 

Output: 

Find quotient and remainder in java | codeYourslf ๐Ÿ‘จ‍๐Ÿ’ป

public class quotientByMethod {

  public static void main(String[] args) {

    findValue fv = new findValue();

    int quotient = fv.getQuotient(30, 5);

    int reminder = fv.getReminder(30, 5);

    System.out.println("The quotient is: " + quotient);

    System.out.println("The reminder is: " + reminder);

  }

}

class findValue {

  int getQuotient(int dividend, int divisor) {

    return dividend / divisor;

  }

  int getReminder(int dividend, int divisor) {

    return dividend % divisor;

  }

}

 

Logic for this problem i.e how to find quotient and remainder in java

Please read the logic part here, as a result you can easily understood how to write a java program to find the quotient and remainder.

What is quotient and remainder :-  

- we all know, to perform a division we must need dividend and divisor. And by doing division we can get quotient and remainder.

- First we have to clear about dividend and divisor, the number which we want to divide is known as dividend. And by which number we are going to divide, is called divisor.

- Ex : let's see we want to divide 15 by 5, here dividend = 15 and divisor = 5.

- And what ever the results we are going to get when we divide 15 with 5 will be quotient and after complete division, if something not divisible that remaining number will be the remainder.

Find quotient and remainder in java | codeYourslf ๐Ÿ‘จ‍๐Ÿ’ป

Here quotient = 3, and remainder = 0. Here remainder is 0, because 15 is completely divisible by 5.  

- If we divide 15 with 6, then here ..

  • Dividend = 15
  • Divisor = 6,
  • Quotient will be 2 and remainder will be 3.

How to implement logic in java: 

๐Ÿ‘‰ In java programming we division operator( / ) which return the quotient of a number. And modulus operator( % ) which gives the remainder.

 Ex :- int quotient = 15 / 6 ;

         int remainder = 15 % 6 ; 

In this process we can find the remainder and quotient of any number by using java programming language.

Here I have used my mobile to code the problem statement. 


`

2 comments

  1. Hey please paste your comment here
    1. Carry on ...
Hey Please ๐Ÿ‘, feel free to share your opinion ๐ŸŒ
© codeYourslf. All rights reserved. Distributed by Pixabin