
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program for Smallest K digit number divisible by X
To find the smallest K digit number divisible by X, the Java code is as follows −
Example
import java.io.*; import java.lang.*; public class Demo{ public static double smallest_k(double x_val, double k_val){ double val = 10; double MIN = Math.pow(val, k_val - 1); if (MIN % x_val == 0) return (MIN); else return ((MIN + x_val) - ((MIN + x_val) % x_val)); } public static void main(String[] args){ double x_val = 76; double k_val = 3; System.out.println("The smallest k digit number divisible by x is "); System.out.println((int)smallest_k(x_val, k_val)); } }
Output
The smallest k digit number divisible by x is 152
A class named Demo contains a function anmed ‘smallest_k’. This function returns the minimum number of digits of ‘k’ that completely divide the number ‘x’. In the main function, a value for ‘x’ and ‘k’ is defined. The function is called with these values and the relevant message is displayed on the console.
- Related Articles
- Python Program for Smallest K digit number divisible by X
- C++ Program for Smallest K digit number divisible by X?
- C++ Programming for Smallest K digit number divisible by X?
- Java Program for Largest K digit number divisible by X
- C++ Program for Largest K digit number divisible by X?
- C++ Program for the Largest K digit number divisible by X?
- Largest K digit number divisible by X in C++
- Smallest Integer Divisible by K in Python
- Find nth number that contains the digit k or divisible by k in C++
- Which is the smallest 4-digit number divisible by 8, 10 and 12?
- Find the smallest 5-digit number which is divisible by 12, 18, 30.
- Find the smallest 4-digit number which is divisible by 18,24 and 32 .
- Find the smallest 5 digit number which is exactly divisible by 20,25 and 30.
- Determine the smallest 3-digit number which is exactly divisible by 6,8 and 12.
- Find the smallest 4 digit number which is exactly divisible by 18, 24, 36.

Advertisements