Java program to find the largest digit of a number - AskTheCode

Find the largest digit of a number in Java | Java Programming Solutions | Ask The Code


Looping a number and taking away each digit of it is so much fun, but I wanted to try out a much more complex task: getting the largest digit among them all.

Think you can handle the job?

Input Sample:


Output Sample:



import java.util.Scanner;

class solution_Lar_Digit{

public static void main(String[] args) {

Scanner sc = new Scanner(;

int n = sc.nextInt();

int max = 0;

while(n != 0){

int val = n % 10;

if (val > max) {

max = val;


n = n / 10;





9 views0 comments

Recent Posts

See All

Calculate BMI in Java | AskTheCode

Write a Java program that reads values for weight in kilograms and height in centimeters and prints out the BMI... interpretation of it...

"Believe you can and you're halfway there"