fork download
  1. import java.util.Scanner;
  2. public class Main {
  3. static int multiplication(int x) {
  4. int mul = 1;
  5. while(x != 0) {
  6. mul *= x % 10;
  7. x /= 10;
  8. }
  9. return mul;
  10. }
  11. public static void main (String[] args) {
  12. Scanner scanner = new Scanner(System.in);
  13. int n = scanner.nextInt();
  14. int maxmul = multiplication(n);
  15. int copy = n;
  16. int i = 10;
  17. while(n!= 0) {
  18. int temporary_number = (copy / (i / 10)) % 10;
  19. int left = copy / i;
  20. int right = copy % (i / 10);
  21. if(temporary_number != 9) {
  22. temporary_number = 9;
  23. copy = ((left - 1) * 10 + temporary_number) * (i / 10) + right;
  24. }
  25. n /= 10;
  26. i *= 10;
  27. int mul = multiplication(copy);
  28. if(maxmul < mul) maxmul = mul;
  29. }
  30. System.out.println(maxmul);
  31. }
  32.  
  33. }
Success #stdin #stdout 0.1s 35480KB
stdin
10
stdout
9