Question: how would i modify the following Java code to make it modular? import java.util.Scanner; public class Perfect { public static void main(String[] args) { int

how would i modify the following Java code to make it modular?

import java.util.Scanner;

public class Perfect

{

public static void main(String[] args)

{

int n, sum = 0;

try (Scanner s = new Scanner(System.in)) {

System.out.print("Enter any integer you want to check:");

n = s.nextInt();

}

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

{

if(n % i == 0)

{

sum = sum + i;

}

}

if(sum == n)

{

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

}

else

{

System.out.println("The number is not a perfect number");

}

}

int divisor(int x)

{

return x;

}

}

it calculates whether or not an input integer is a perfect number or not (Equal to the sum of its divisors)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!