Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

Would you change the ending of the book? If so, how?

Answered: 1 week ago

Question

What are the APPROACHES TO HRM?

Answered: 1 week ago