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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:52:07+00:00 2026-05-24T12:52:07+00:00

How do i print out a set of integers in an args array. I

  • 0

How do i print out a set of integers in an args array. I intend to have an output of: The numbers are 1, 2, 3, 4, 5

System.out.println("The numbers are ");
    for(int i=0; i< args.length;i++)
    System.out.print(args[i] + " ";

The compiler gives me an error of “i cannot be resolved to a variable” When i resolve it with “int b = 0;” it gives me a single integer, rather than the integers in args

  • 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-05-24T12:52:09+00:00Added an answer on May 24, 2026 at 12:52 pm

    As of Java 5 you can also skip i entirely:

    for( String arg : args )
       System.out.print(arg + " ");
    

    Additionally, I’d like to advocate using curly braces even for one-statement blocks.
    It’s easier to read and less likely to change the behavior by adding a statement (like some log statement).

    Example, a naive pow() method (checks skipped for simplicity):

    Orignal code:

    int pow(int base, int power) { //assume power to be > 1
     int result = base;
    
     for( int i = 1; i <= power; i++ ) 
       result *= base;
    
     return result;
    }
    

    Now I’d like to log the result in each step:

    int pow(int base, int power) { //assume power to be > 1
      int result = base;
    
      for( int i = 1; i <= power; i++ ) 
        System.out.println( base + " pow( " + i + ") = " + result );
        result *= base;
    
      return result;
    }
    

    Suddenly, I get a wrong result for power > 2, since now result *= base; is only executed once (it is now outside the loop).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get print out invoice but also wanna set margins and page
i need to print out numbers 1-100 in a random order. the print statement
I have 100 points to dole out to a set of items. Each item
Say that I have a set of numbers: Group1 = 10, Group2 = 15,
I have an array of integers, which could run into the hundreds of thousands
Anyone point me the set of defined rules to find out the eligibility for
I need to print out data into a pre-printed A6 form (1/4 the size
Can i print out a url /admin/manage/products/add of a certain view in a template?
I'm trying to print out the date in a certain format: NSDate *today =
Attempting to print out a list of values from 2 different variables that are

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.