×

Java Programs

Java Practice

Java program to demonstrate the Math.floorDiv() method

Java example to demonstrate the Math.floorDiv() method.
Submitted by Nidhi, on May 17, 2022

Problem statement

In this program, we will read two integer numbers from the user using the Scanner class. Then we will use the Math.floorDiv() method. The Math.floorDiv() method returns the largest integer value that is less than or equal to the algebraic quotient.

Java program to demonstrate the Math.floorDiv() method

The source code to demonstrate the Math.floorDiv() method is given below. The given program is compiled and executed successfully.

// Java program to demonstrate the 
// Math.floorDiv() method

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner X = new Scanner(System.in);

    int num1 = 0;
    int num2 = 0;

    System.out.print("Enter number1: ");
    num1 = X.nextInt();

    System.out.print("Enter number2: ");
    num2 = X.nextInt();

    System.out.print("Result: " + Math.floorDiv(num1, num2));
  }
}

Output

Enter number1: -25
Enter number2: 3
Result: -9

Explanation

In the above program, we imported the "java.util.*" package to use the Scanner class. Here, we created a public class Main that contains a main() method.

The main() method is the entry point for the program. Here, we created a variable num of double type and then we used Math.floorDiv() method. It returns the largest integer value that is less than or equal to the algebraic quotient.

Java Math Class Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.