How to find the lowest digit in int number with Java

1 Answer

0 votes
public class MyClass {
    public static int getTheLowestDigit(int n) {
        int min = 9;
        while(n != 0) {
            if (n % 10 < min) min = n % 10;
            n /= 10;
        }
        return min;
    }
    public static void main(String args[]) {
        int n = 213;
        System.out.println(getTheLowestDigit(n));
       
        n = 76594;
        System.out.println(getTheLowestDigit(n));
       
        n = 76529;
        System.out.println(getTheLowestDigit(n));
    }
}



/*
run:

1
4
2

*/

 



answered Jun 7, 2020 by avibootz

Related questions

1 answer 163 views
1 answer 215 views
2 answers 199 views
1 answer 142 views
1 answer 179 views
1 answer 161 views
...