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 8853105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:34:02+00:00 2026-06-14T13:34:02+00:00

Method testPerfect is supposed to receive a number from getPerfect , factor the number

  • 0

Method testPerfect is supposed to receive a number from getPerfect, factor the number and put the numbers in an array.
I currently have the array printing, but all zeros. Any suggestions as to put the factors of a number into an array?

public class aermel_Perfect
{
public static void main ( String args [] )
{
    int gN;
    int gP = getPerfect();
    int [] array = new int[100];
    //int printFactors;
    System.out.println(Arrays.toString(array));
}


public static int getNum() //Get amount of numbers to check
{
Scanner input = new Scanner ( System.in );
System.out.print( "How many numbers would you like to test? " );
int count = input.nextInt();
int perfect = 1;
boolean vN = validateNum(count, perfect);
while(!vN)
{
    System.out.print (" How many numbers would you like to test? ");
    count = input.nextInt();
    vN = validateNum(count, perfect);
}
return count;
}   

public static boolean validateNum( int count, int perfect  ) //Check if number is valid
{
if (( count <= 0) || ( perfect <= 0))

{ 
    System.out.print( "Non-positive numbers are not allowed.\n");
}



else 
{
    return true;
}
return false;


}
public static int getPerfect() //Gets the numbers to test
{
Scanner input = new Scanner ( System.in );
int perfect = -1;
int count = getNum();
System.out.print("Please enter a perfect number: " );
perfect = input.nextInt();  
boolean vN = validateNum(perfect, count);
while (!vN) 
{
    System.out.print("Please enter a perfect number: ");
    perfect = input.nextInt();
    vN=validateNum(perfect, count);
}
return perfect;
}


public static int[] testPerfect( int perfect, int[] array )

{
testPerfect(perfect, array);
int limit = (int) Math.ceil(Math.sqrt(perfect));
int index = 0;
for ( int i = 1; i <=limit; i++)
{
    array[index++] = i;
    perfect /= i;
}
array[index] = perfect;

return array;


}






}
  • 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-14T13:34:04+00:00Added an answer on June 14, 2026 at 1:34 pm

    Something like that maybe?
    First you need to call the testPerfect() from your main with the gP received from getPerfect() and the array as parameter.
    Second you need to remove the call testPerfect() which is the first line of the method testPerfect() else this would result in an infinite recursive calls.

    public class aermel_Perfect
    {
    public static void main ( String args [] )
    {
        int gN;
        int gP = getPerfect();
        int [] array = new int[100];
        array=testPerfect(gP,array);
        //int printFactors;
        System.out.println(Arrays.toString(array));
    }
    
    
    public static int getNum() //Get amount of numbers to check
    {
    Scanner input = new Scanner ( System.in );
    System.out.print( "How many numbers would you like to test? " );
    int count = input.nextInt();
    int perfect = 1;
    boolean vN = validateNum(count, perfect);
    while(!vN)
    {
        System.out.print (" How many numbers would you like to test? ");
        count = input.nextInt();
        vN = validateNum(count, perfect);
    }
    return count;
    }   
    
    public static boolean validateNum( int count, int perfect  ) //Check if number is valid
    {
    if (( count <= 0) || ( perfect <= 0))
    
    { 
        System.out.print( "Non-positive numbers are not allowed.\n");
    }
    
    
    
    else 
    {
        return true;
    }
    return false;
    
    
    }
    public static int getPerfect() //Gets the numbers to test
    {
    Scanner input = new Scanner ( System.in );
    int perfect = -1;
    int count = getNum();
    System.out.print("Please enter a perfect number: " );
    perfect = input.nextInt();  
    boolean vN = validateNum(perfect, count);
    while (!vN) 
    {
        System.out.print("Please enter a perfect number: ");
        perfect = input.nextInt();
        vN=validateNum(perfect, count);
    }
    return perfect;
    }
    
    
    public static int[] testPerfect( int perfect, int[] array )
    
    {
    //testPerfect(perfect, array);
    int limit = (int) Math.ceil(Math.sqrt(perfect));
    int index = 0;
    for ( int i = 1; i <=limit; i++)
    {
        array[index++] = i;
        perfect /= i;
    }
    array[index] = perfect;
    
    return array;
    
    
    }
    
    
    
    
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

get1() method returns an array. I do get the output but the value from
One method of debugging within the Controllers I have learnt from Django is to
Method keySet() . Examples works fine, but I not sure if I'm right.
in method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath usually you use an array to
Quick method description: I have two tables, lets name them table ONE and table
The method in question is below. This method is supposed to take a string
This method accepts as the last argument an integer, but I'm not sure I
Inside Method A, there is method B. Method B throws exception, but method A
This method works OK, but if I add delayed_job's handle_asychronously, I get can't convert
A method have some methods and also some methods have other methods. How should

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.