package com.x.xyz; public class HelloWorld { public static void main(String[] args) { System.out.println("Star !"); System.out.println(trailingZeroes(0)); System.out.println(trailingZeroes(1)); System.out.println(trailingZeroes(2)); System.out.println(trailingZeroes(3)); System.out.println(trailingZeroes(4)); System.out.println(trailingZeroes(5)); System.out.println(trailingZeroes(6)); System.out.println(trailingZeroes(7)); } public static int trailingZeroes(int n) { int sum = 10; // if(0 == n) { // return 1; // } // for(int i=1; i<n; i++) { // sum = sum * 10; // } // return sum; if(0 == n) { return 1 * sum; }else{ return trailingZeroes(n-1) * sum; } } }
Star !
10
100
1000
10000
100000
1000000
10000000
100000000
时间: 2024-10-13 16:54:21