

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- C++ Program for Smallest K digit number divisible by X?
- Python 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++
- Is the digit divisible by the previous digit of the number in JavaScript
- Count n digit numbers divisible by given number in C++
- Largest N digit number divisible by given three numbers in C++
- Smallest number formed by shuffling one digit at most in JavaScript
- Smallest number that is divisible by first n numbers in JavaScript
- Program to count number of trailing zeros of minimum number x which is divisible by all values from 1 to k in Python
Advertisements