Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple Java homework
    text
    copied!<p>So I'm a java newby and I'm doing this homework assignment that asks me to write a program to find the first four perfect numbers. I think I have everything roughly correct, though I am unable to test my program due to an error message that reads 'Exception in thread "main" javva.lang.NoSuchMethodError: main' when I try to run my program. It compiled fine and I think all the math is right:</p> <pre><code>import java.awt.*; public class PerfectNumbers { int num = 1, divisor1 = 1, divisor2, divSum, perfNum1, perfNum2, perfNum3, perfNum4; public void main() { do { while (num != divSum) { if (num % divisor1 == 0 &amp;&amp; divisor1 != Math.sqrt(num)) { divSum += divisor1; divisor2 = num / divisor1; divSum += divisor2; divisor1++; } else if (num % divisor1 !=0 &amp;&amp; divisor1 != Math.sqrt(num)) divisor1++; else if (divisor1 == Math.sqrt(num)) { divSum += Math.sqrt(num); divisor1 = 1; } } if (num == divSum &amp;&amp; perfNum1 == 0) { perfNum1 = num; num++; divSum = 0; } else if (num == divSum &amp;&amp; perfNum2 == 0) { perfNum2 = num; num++; divSum = 0; } else if (num == divSum &amp;&amp; perfNum3 == 0) { perfNum3 = num; num++; divSum = 0; } else if (num == divSum &amp;&amp; perfNum4 == 0) { perfNum4 = num; break; } } while (perfNum4 == 0); if (perfNum4 == 0) System.out.print("The first four perfect numbers are " + perfNum1 + ", " + perfNum2 + ", " + perfNum3 + ", " + perfNum4 + "."); } } </code></pre> <p>P.S. any advice on newb mistakes on syntax or style would be greatly appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload