Sunday, June 21, 2020

Write a program to find the Factors or all Divisors of number? (6..fector…(1,2,3,6) )

29)  Write a program to find the Factors or all Divisors of number? (6..fector…(1,2,3,6) )

import java.util.*;
public class Factors
{
   public static void main(String args[ ])
    {
        Scanner sc = new Scanner (System.in);
        System.out.println("Enter a number");
        int a = sc.nextInt();
        System.out.print("Factors of "+a+" = ");
        for(int i=1;i<=a;i++)
        {
            if(a%i==0)
            System.out.print(i+" ");
        }
    }
}

No comments:

Post a Comment

if you have any doubts, Please let me know.
Your Truly
Shashank Porwal

 jhvghvgk ;nkjn ,nkjhj