6. Write a program that prints every perfect number from 1 through 1000. A perfe
ID: 3625874 • Letter: 6
Question
6. Write a program that prints every perfect number from 1 through 1000. A perfect number is one that equals the sum of all the numbers that divide evenly into it. For example, 6 is perfect because 1, 2 and 3 divide evenly into it, and their sum is 6. Save the program as Perfect.java
7. Write a program that calculates the amount of money earned on an investment; that amount should include 12 percent interest. Prompt the user to choose the investment amount from one menu and the number of years for the investment from a second menu. Display the total amount (balance) for each year of the investment. Use loop instruction to calculate the balance for each year. Use the formula
amount = investment*(1+ interest) raised to a power equal to the year to calculate the balance. Use the Math power function from Chapter 4, Math.pow(x,y) where x=(1+ interest) and y is the year. Save program as Investment.java
(In the prompt or input of the user you can choose either console system.in.read() or the JOptionPane.)
Explanation / Answer
please rate - thanks
public class perfect
{public static void main(String[] args)
{int i,num,sum;
System.out.println("The perfect numbers between 1 and 1000 are");
for(num=1;num<=1000;num++)
{ sum=0;
for(i=1;i<num;i++)
if(num%i==0)
sum+=i;
if(sum==num)
{System.out.print(num+" ");
}
}
}
}
----------
sorry
CRAMSTER RULES are 1 question per post. This is 2 totally unrelated questions
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.