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

The Archive Base Latest Questions

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

I’m having some troubles with the beginning of this program. It’s supposed to take

  • 0

I’m having some troubles with the beginning of this program.
It’s supposed to take a number and determine whether or not it is perfect.
Currently I have it asking how many numbers to check, whenever I input any positive number, it asks again.
AND, whenever I input a negative number for the second question, the program ends and doesn’t prompt again.
Any ideas on how to fix this?

import java.util.Scanner;

public class aermel_Perfect
{
public static void main ( String args [] )
{
    int gN = getNum();
    int gP = getPerfect();
}


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);
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);
return perfect;
}
}
  • 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:24:59+00:00Added an answer on June 14, 2026 at 1:24 pm

    Use a while loop in your get methods e.g. to repeatedly ask for input until a valid number is entered.

        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.println("Invalid input. Try again");
              count = input.nextInt();
              vN = validateNum(count, perfect);
          }
          return count;
        } 
    

    Simiilarly, update the getPerfect method and remove int count = getNum(); statement from this method.

    EDIT: To repeatedly ask for perfect number count times, update your main method as below:

       public static void main ( String args [] )
       {
          int gN = getNum();
          for(int indx=0; indx <gN; indx++){
             int gP = getPerfect();
             //use your gP numbers in the way you want
          }
       }
    

    EDIT1: To call How many numbers would you like to test? " tow times, I think you can simply call your getNum() method two times in the main method as below:

       public static void main ( String args [] )
       {
          int gN = getNum();//first call
          gN = getNum(); //second call
          int gP = getPerfect();
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build

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.