Computer Science, asked by kanupriya163, 1 month ago

write a Java Program for class 9 to input a number. find the sum of all its factors excluding the number itself. if the sum of the factors is equal to the number itself, then print the message "it's the perfect number"​

Answers

Answered by ktr1705
4

Answer:

/* Perfect number :

* Perfect number => when the addition of the factors of the number is equal to the number itself

*/

Main Code:

import java.util.*;

public class Perfect_num ber

{

   public static void main (String[]args) {

      Scanner sc = new Scanner (System.in);

      int num, i = 1, factors = 0;

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

      num = sc.nextInt();

      System.out.println("The factors of " + num + " are :");

      for (i = 1; i < num; i++) {

           if (num % i == 0) {

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

               factors += i;

           }

      }

       if (factors == num) {

           System.out.println("");

           System.out.println(num + " is a perfect number.");

       }

       else if (factors != num){

           System.out.println("");

           System.out.println(num + " is NOT a Perfect number.");

      }

   }  

--------------------------------------

For more doubts in computers and programming, follow me to get the best explanations! Hope this answer was helpful to you!

Please mark my answer as the brainliest. It would mean a lot to me!

Answered by sheejujayachandran16
0

Answer:

Explanation:

i dont know

Similar questions