Disclosure: When you purchase a service or a product through our links, we sometimes earn a commission.

# Java Program to show Maximum and Minimum

September 17, 2017

This Java program prints the maximum and the minimum number of a given numerical digit.

For example – typical output would be

42308

and theoutput is –  minimum digit is 0 and the maximum digit is 8

``````

/** Method that shows the minimum and maximum digit
*of any given number
**/
import java.util.*;
public class MaxMin {

static void maxMin(int number){

int digit = 0;
int min = number;
int max = 0;

while (number!=0){

digit = number%10;
number = number/10;

if(max < digit){ max = digit; } if( min > digit) {
min = digit;
}
}
System.out.println("Max: " + max);
System.out.println("Min: " + min);
}

public static void main( String[] args) {

Scanner console = new Scanner(System.in);

// Make sure user enters only int number
while(!console.hasNextInt()) {
System.out.println("Please enter an int number " +
"maximum of 10 digits");
console.next();}

int number = console.nextInt();

maxMin(number);

}
}

``````

## 7 comments on “Java Program to show Maximum and Minimum”

1. I’m commenting to let you be aware of of the amazing discovery my child developed browsing the blog. She came to find a good number of details, including how it is like to have a great coaching character to get a number of people clearly completely grasp a number of advanced issues. You actually did more than her desires. I appreciate you for churning out such beneficial, dependable, edifying and cool guidance on that topic to Emily.

2. A lot of thanks for all your efforts on this site. Gloria loves engaging in investigation and it’s easy to understand why. Almost all know all concerning the dynamic means you deliver helpful items on the web blog and as well encourage contribution from other people on that concern plus our daughter is actually discovering a lot. Have fun with the remaining portion of the new year. You’re the one conducting a good job.

3. I’m also commenting to let you be aware of of the excellent discovery my cousin’s child enjoyed checking your blog. She discovered a wide variety of details, most notably how it is like to have a marvelous coaching heart to get many more effortlessly fully understand certain complicated matters. You actually did more than my desires. I appreciate you for displaying such great, healthy, educational and also cool guidance on that topic to Evelyn.

4. I happen to be writing to make you understand what a wonderful experience our princess went through visiting yuor web blog. She realized too many things, with the inclusion of what it is like to possess an incredible teaching style to make the rest without problems understand various very confusing topics. You undoubtedly surpassed visitors’ expected results. Thanks for supplying those warm and helpful, trustworthy, revealing not to mention unique tips on your topic to Tanya.

5. Thanks for your whole work on this website. My niece takes pleasure in working on research and it is simple to grasp why. We all notice all relating to the powerful ways you render vital tips and tricks via your website and therefore welcome response from website visitors on this topic while our own simple princess is without question understanding so much. Take pleasure in the rest of the year. Your performing a very good job.