
- 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 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 Articles
- 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++
- 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?
- Find the largest 4 digit number divisible by 16.
- 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
- Program to Find Out the Largest K-Divisible Subsequence Sum in Python
- Count n digit numbers divisible by given number in C++
- Program to count number of trailing zeros of minimum number x which is divisible by all values from 1 to k in Python

Advertisements