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

  • Home
  • SEARCH
  • 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 7937041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:24:47+00:00 2026-06-03T22:24:47+00:00

My task in this lab is to accept multiple input file and the format

  • 0

My task in this lab is to accept multiple input file and the format is similar in all of them except that some files have comments and I want to skip the comments lines. For example:

Input file:

Input file 1

#comment: next 5 lines are are for to be placed in an array
blah 1
blah 2
blah 3 
blah 4
blah 5

#comment: next 2 line are to be placed in a different array
blah 1 
blah 2

#end of input file 1

What I tried doing was I used 2 while loops (I can post my code if needed). I did the following

while(s.hasNext()) {
    while(!(s.nextLine().startWith("#")) {
        //for loop used to put in array
        array[i] = s.nextLine();
    }
}

I feel like this should work but it does not. What am I doing incorrect. Please help. Thank you in advance.

  • 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-03T22:24:49+00:00Added an answer on June 3, 2026 at 10:24 pm

    There are two problems with your code:

    1. You are invoking nextLine more than once within the loop.
    2. Your second while loop will fail if there is no next line.

    Try modifying code as follows:

    int i = 0;
    while(s.hasNextLine()) {
        String line = s.nextLine();
        if(!line.startWith("#")) {
              array[i++] = line;
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a function that performs some task (this is in Python pseudocode):
I have this task: sum all numbers in string and perform multiplication input: 3
Please explain what this task is about? Create a generic linked list class that
I have some basic idea on how to do this task, but I'm not
I have some code like this: public void SaveImage(int Counter) { var task =
Is this a 'real' task, that can be written on any language ( C/C++,
For this task I'm supposed to create a wannabe network that is supposed to
For the this task I'm supposed to find all the names of actors who
I want to automate some GUI tasks using Selenium. And integrate this task in
I had this task to read a file, store each character in a dict

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.