Note that there are some explanatory texts on larger screens.

plurals
  1. POboolean return issue/getting factors from method put into an array
    primarykey
    data
    text
    <p>after posting an hour ago about an earlier issue and getting a response within 4 min which was insane ill try my luck one more time. program has 5 methods, am currently making all of them so they will not all be on here(putting this in due to prior response) issue now is getting one of my last methods that actually does something other than making a print statement to work correctly. the method is not complete it needs to not only find the factors of said number but then also has to store them in an array, add them up and them determine if the number is perfect. the last method not shown is going to print out the actual array for each number if it has one. "testperfect" is the method i am having issues with, in eclipse i am getting an error saying this method must return result in type boolean. . . any sort of help would be appreciated</p> <pre><code>import java.util.Scanner; public class tgore_perfect { private static int count; private static int perfect; public static void main ( String args []) { count = getNum (); //System.out.print(count); boolean check = validateNum(); //System.out.print(check); while (validateNum() == false) { System.out.print ("Non-positive numbers are not allowed.\n"); count = getNum(); } if (validateNum() == true) { for ( int i = 0; i &lt; count; i++ ) { perfect = getPerfect(); testPerfect(); } } } public static int getNum () //gets amount of numbers to process { Scanner input = new Scanner ( System.in ); int counter; System.out.println ("How many numbers would you like to test? "); counter = input.nextInt(); return counter; } private static boolean validateNum() //checks user input { if (count &lt;= 0) { return false; } else { return true; } } public static int getPerfect() //gets number to process { Scanner input = new Scanner ( System.in); perfect = -1; System.out.print ("Please enter a possible perfect number: "); return perfect = input.nextInt(); } public static boolean testPerfect() //tests the number to see if is perfect { int sum = 0; int x = 0; for( int i = 1; i &lt; perfect; i++ ) { if((perfect % i ) == 0 ) { x = i; sum += x; } if( x == perfect) { return true; } else { return false; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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