一定要注意…………审题!!!!
1 public boolean isUgly(int num) { 2 if(num <= 0) { 3 return false; 4 } 5 if(num == 1) { 6 return true; 7 } 8 while(num % 2 == 0) { 9 num /= 2; 10 } 11 while(num % 3 == 0) { 12 num /= 3; 13 } 14 while(num % 5 == 0) { 15 num /= 5; 16 } 17 System.out.println(num); 18 return (num == 1 || num == -1)? true: false; 19 }
时间: 2024-10-18 00:36:37