Hello! Tell me by code, I can not figure out where it is wrong, sometimes in my program it incorrectly shows the highest number of a three-digit number. The program is composed on the instructions:
Create a program that displays a randomly generated three-digit natural number and its largest digit.
public class Test { public static void main(String args []) { final int min = 100; final int max = 999; int first; int second; int third; int value_max; int value = (int) (min + Math.random() * (max - min)) ; if(value > min && value < max) { first = (int) Math.floor(value / 100); second = (int) Math.floor((value - first * 100) / 10); third = (int) Math.floor(value - first * 100 - second * 10); System.out.println("Трехзначное число = " + value); if(first > second) { value_max = first; if(value_max < third) { value_max = third; } else { value_max = second; } } else { value_max = second; } if(value_max < third) value_max = third; System.out.println("Первое число = " + first); System.out.println("Второе число = " + second); System.out.println("Третье число = " + third); System.out.println("Максимальное число = " + value_max); } } }
And there is another question: by what formula can one calculate also the largest digit of four and five-digit numbers, etc.