Computer Science, asked by shwetasharma9332, 3 months ago

Write a program in Java to calculate the sum of divisors of an integer input by the user by input by the input method. ​

Answers

Answered by Shishaa
0

Check it out on geeksforgeeks website

Answered by dreamrob
0

Program:

import java.util.*;

class HelloWorld

{

   public static void main(String[] args)

   {

       Scanner Sc = new Scanner(System.in);

        int n;

        System.out.print("Enter a number : ");

        n = Sc.nextInt();

        int sum = 0;

        for(int i = 1 ; i <= n ; i++)

        {

            if(n % i == 0)

            {

                System.out.print(i + "\t");

                sum = sum + i;

            }

        }

        System.out.print("\nSum of divisors = " + sum);

   }

}

Output:

Enter a number : 10

1 2 5 10  

Sum of divisors = 18

Similar questions