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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:27:09+00:00 2026-06-06T18:27:09+00:00

I have a program, which takes a parameter from the args[] array, defined in

  • 0

I have a program, which takes a parameter from the args[] array, defined in the main method, but has a backup in case that isn’t defined, in the form of a try…catch block, which, if an ArrayIndexOutOfBounds exception is thrown, instead uses a method called getInt to prompt the user to enter a variable. But, for some reason, when I try to use that variable, my compiler says that it cannot find it. I have the following code:

try {
    int limit = Integer.parseInt(args[0]);
}
catch(ArrayIndexOutOfBoundsException e) {
    int limit = getInt("Limit? ");
}
int[] p = getPrimes(limit);

getPrimes is another method I have, which returns an array of prime numbers starting from 2 and up to a specified number (using the Sieve of Atkin). Anyway, when I write int[] p = getPrimes(limit); and try compiling, it says that the “limit” variable is not defined. Help please!

  • 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-06T18:27:10+00:00Added an answer on June 6, 2026 at 6:27 pm

    You should declare it outside the block:

    int limit;
    try {
        limit = Integer.parseInt(stuff[0]);
    }
    catch(ArrayIndexOutOfBoundsException e) {
        limit = getInt("Limit? ");
    }
    int[] p = getPrimes(limit);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program Sample which takes input both from stdin and a non-standard
I have a program which takes a long time to complete. I would like
I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and
I have wrote the code below which was taken from Java How to program
I have a program with two methods. The first method takes two arrays as
I would like to build a program which takes a username as parameter and
Here, i have a program, which takes arguments (how surprising...). I want him to
I've got a method which currently takes an IList as a parameter, where UserBO
I have a program which takes various command line arguments. For the sake of
I have a WCF Service operation which takes an object as a parameter. This

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.