You are here: Home / Topics / Program to find Maximum number from digits of any number in Java

Program to find Maximum number from digits of any number in Java

Filed under: Java on 2023-08-18 06:56:52

// Maximum digit from number

public class MaximumDigit {

   public static void main(String[] args) {
       int i = 235;
       int temp = 0;
       while (i > 0) {
           int r = i % 10;
           i = i / 10;
           if (temp < r) {
               temp = r;

           }
       }
       System.out.println("Max digit is "+temp);
   }
}


Output:

Max digit is 5

About Author:
Y
Yatendra Sir     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.