I\'m looking for help on Part 2 (Extra Credit) of this question. I have attached
ID: 3653526 • Letter: I
Question
I'm looking for help on Part 2 (Extra Credit) of this question. I have attached the completed code and question.
Part I answered code:
import java.util.*;
public class calculate
{
static int sum_divisors(int n)
{
int sum=0;
for(int i=1;i<=n;i++)
{
if(n%i==0) sum+=i;
}
return sum;
}
public static void main(String args[])
{
Scanner s = new Scanner(System.in);
System.out.print("Enter the value for N: ");
int N=s.nextInt();
System.out.println("N Abundand Deficient Perfect Prime");
int ca=0;
int cd=1;
int cp=0;
int cpr=0;
System.out.println("1 0 1 0 0 ");
for(int i=2;i<=N;i++)
{
int sd=sum_divisors(i);
if(sd>2*i) ca++;
if(sd<2*i) cd++;
if(sd==2*i) cp++;
if(sd==(1+i)) cpr++;
System.out.println(Integer.toString(i)+" "+Integer.toString(ca)+" "+Integer.toString(cd)+" "+Integer.toString(cp)+" "+Integer.toString(cpr));
}
}
}
Explanation / Answer
import java.util.*; public class calculate { static int sum_divisors(int n) { int sum=0; for(int i=1;iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.