Created
          May 29, 2021 15:13 
        
      - 
      
 - 
        
Save bijay-shrestha/309545651a0ed7be6e8898f335a41ae3 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.hawa.practice; | |
| import lombok.extern.slf4j.Slf4j; | |
| @Slf4j | |
| public class FactorsOfNumber { | |
| public static void main(String[] args) { | |
| int num = 10; | |
| log.info("The factors of {} are {}", num, getFactorsOfNumber(num)); | |
| } | |
| static int[] getFactorsOfNumber(int n) { | |
| int x = 0; | |
| int[] arr = new int[countFactorsOfNumber(n)]; | |
| for (int i = 1; i <= n; i++) { | |
| if (n % i == 0) { | |
| arr[x] = i; | |
| x++; | |
| } | |
| } | |
| return arr; | |
| } | |
| static int countFactorsOfNumber(int num) { | |
| int count = 0; | |
| for (int i = 1; i <= num; i++) { | |
| if (num % i == 0) { | |
| count++; | |
| } | |
| } | |
| return count; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment