

- 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 Largest K digit number divisible by X
Following is the Java program for largest K digit number divisible by X −
Example
import java.io.*; import java.lang.*; public class Demo{ public static int largest_k(int val_1, int val_2){ int i = 10; int MAX = (int)Math.pow(i, val_2) - 1; return (MAX - (MAX % val_1)); } public static void main(String[] args){ int val_1 = 25; int val_2 = 2; System.out.println("The largest 2 digit number divisible by 25 is "); System.out.println((int)largest_k(val_1, val_2)); } }
Output
The largest 2 digit number divisible by 25 is 75
A class named Demo contains a function ‘largest_k’ that is used to find the largest ‘k’ (val_1) digit number that can be divided by another value (val_2). Here, another variable named ‘MAX’ is defined and the difference between MAX and (MAX % val_1) is returned. The main function defines two values for ‘x’ and ‘k’ respectively. The ‘largest_k’ function is called on these values and the output is displayed on the console.
- Related Questions & Answers
- C++ Program for Largest K digit number divisible by X?
- C++ Program for the Largest K digit number divisible by X?
- Java Program for Smallest K digit number divisible by X
- Largest K digit number divisible by X in C++
- 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?
- Largest N digit number divisible by given three numbers in C++
- Find nth number that contains the digit k or divisible by k in C++
- Largest number smaller than or equal to N 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++
- Program to Find Out the Largest K-Divisible Subsequence Sum in Python
- Program to count number of trailing zeros of minimum number x which is divisible by all values from 1 to k in Python
- Subarray Sums Divisible by K in C++
Advertisements