Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8830807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:10:38+00:00 2026-06-14T08:10:38+00:00

after posting an hour ago about an earlier issue and getting a response within

  • 0

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

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 < 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 <= 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 < perfect; i++ )
 {
     if((perfect % i ) == 0 )
     {
         x = i;
         sum += x;

     }
     if( x == perfect)
     {
         return true;
     }
     else 
     {
         return false;
     }
}
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:10:39+00:00Added an answer on June 14, 2026 at 8:10 am

    All code-paths must return your return-type

    Imagine if your for-loop did not execute at all because of your values of i and perfect, in that case, your function wouldn’t return anything.

    That isn’t permitted.

    public static boolean testPerfect() //tests the number to see if is perfect
    {
        //...code...
        for( int i = 1; i < perfect; i++ )
        {
            //..code..
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Ignore this, I figured it out about 3 seconds after posting this but
Edit: Of course, immediately after working on it for an hour then posting here,
I suspect I am going to feel really stupid after posting this but here
I want to clear textbox after ajax posting. <div style=padding: 5px; background-color: Silver;> @using
I want to clear textbox after ajax posting. <div style=padding: 5px; background-color: Silver;> @using
I am really posting this out of desperation after searching around a lot for
I am posting to the server using jquery ajax using $.post. After server returns
After discovering about Javascript namespaces, I tried to implement them but I run into
I'm using the Martin Milesich TimePicker, which is basically the jUI datepicker with hour/minute
After posting this question MySQL update or insert or die query I've change to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.