• About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy Policy
  • Change the purpose of use

Tnhelearning.edu.vn - Various useful general information portal

  • Photo
  • Bio
  • How To
  • Tech

How to do division in Java (integer and floating point value)

February 20, 2024 by admin Category: How To

You are viewing the article How to do division in Java (integer and floating point value)  at Tnhelearning.edu.vn you can quickly access the necessary information in the table of contents of the article below.

X

This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.

The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.

This article has been viewed 3,326 times.

There are two types of division in Java—integer division and floating point division (also known as remainder division). Both of these calculations use the up slash (/) as the operator in the divisor / divisor formula. This wikiHow teaches you how to divide two integers (without a decimal point) to get an integer quotient, and how to perform floating point division to get a decimal result.

Table of Contents

  • Steps
    • Integer division
    • Floating point division
  • Advice

Steps

Integer division

Image titled 12966108 1

Image titled 12966108 1

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/2/24/12966108-1.jpg/v4-728px-12966108-1.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/2/24/12966108-1.jpg/v4-728px-12966108-1.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
When dividing two integers in Java, the decimal part (or remainder) is dropped. For example, if you divide 7 by 3 on paper, you get 2 and a remainder of 1. But when you divide two integers in Java, the remainder is omitted and the result is only 2. [1] X Source research To perform integer division, you need to use the following syntax:

 int a = 7 ; int b = 3 ; int result = a / b ; // result will be 2
  • Division of two integers always returns an integer. If you want to get a decimal result when dividing two integers, perform floating point division.
  • If you apply integer division to divide an integer by zero, you’ll get an ArithmeticException at runtime, even if the program compiles well. [2] X Research Source
READ More:   How to Detect Pathological Liars

Floating point division

  • Image titled 12966108 2

    Image titled 12966108 2

    {“smallUrl”:”https://www.wikihow.com/images_en/thumb/3/3a/12966108-2.jpg/v4-728px-12966108-2.jpg”,”bigUrl”:”https:// www.wikihow.com/images/thumb/3/3a/12966108-2.jpg/v4-728px-12966108-2.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,” bigHeight”:546,”licensing”:”<div class=”mw-parser-output”></div>”}
    If the operands in the equation are of type float or double, you need to use remainder division. You can also apply remainder division if you are dividing two numbers and want to get the remainder. To perform this type of division, put the divisor and divisor in the float division syntax. [3] X Research Source With the 7 divided by 3 example, your code would look like this:

     float a = 7.0f ; float b = 3.0f ; int result = a / b ; // result will be 2.33
    • When using remainder division to divide by 0, the result will be NaN (not a number). [4] X Research Sources
  • Advice

    • When performing mixed division of integers and floating-point reals, floating-point values ( float or double ) are automatically converted to double when dividing. [5] X Research Sources
    X

    This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.

    The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.

    This article has been viewed 3,326 times.

    There are two types of division in Java—integer division and floating point division (also known as remainder division). Both of these calculations use the up slash (/) as the operator in the divisor / divisor formula. This wikiHow teaches you how to divide two integers (without a decimal point) to get an integer quotient, and how to perform floating point division to get a decimal result.

    Thank you for reading this post How to do division in Java (integer and floating point value) at Tnhelearning.edu.vn You can comment, see more related articles below and hope to help you with interesting information.

    READ More:   How To Treat Jaundice

    Related Search:

    Related Posts

    How to Create Curved Text in Photoshop
    How to fall asleep faster
    How to Install FBReader to Read eBooks

    Category: How To

    Previous Post: « How to Cure a stuffy nose
    Next Post: How to Remove Splinter from Skin »

    Copyright © 2025 · Tnhelearning.edu.vn - Useful Knowledge