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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:24:24+00:00 2026-06-12T23:24:24+00:00

My code worked when it was in the main method, but once I try

  • 0

My code worked when it was in the main method, but once I try to put it in its own method, I get “args cannot be resolved to a variable” Also, I am very new to java, is there a way to simplify this code block, I have a book that shows modularized code, but it is not explained in detail.

 private static boolean validateInput() {

    //if invalid character is entered ie. a letter, will go to the catch
    try 
    {
        number1 = Integer.parseInt(args[0]);          
    }
    catch (Exception e)
    {
        System.out.println("Input #1 is not a valid integer.");
        return false;
    }

    try
    {
        number2 = Integer.parseInt(args[1]);
    }
    catch (Exception e)
    {
        System.out.println("Input #2 is not a valid integer.");
        return false;
    }

    try
    {
        number3 = Integer.parseInt(args[2]);
    }
    catch (Exception e)
    {
        System.out.println("Input #3 is not a valid integer.");
        return false;

    }
    return true;
}
  • 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-12T23:24:30+00:00Added an answer on June 12, 2026 at 11:24 pm

    You can pass your String[] args as a parameter to validateInput().

    public static void main(String[] args) {
        if (validateInput(args)) {
            ...
        }
    }
    
    private static boolean validateInput(String[] args) {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran this persons code. It worked as a main but when i put
I had code that worked fine when running in the context of the main
My code worked fine in JQuery 1.3.2, but in 1.4.2 it seems to be
The following code worked just fine thank you with one COM client, but with
this piece of code worked fine on my machine, but it doesn't on my
I don't know why, but this code worked for me a month ago... maybe
I am having a problem with code that worked fine in .NET 2.0 but
Its possibly im just missing something here but, when I write some code for
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
This code worked perfectly until a short time ago. The KML and the Javascript

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.