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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:57:02+00:00 2026-05-13T15:57:02+00:00

Hey. You may have recently seen a post by me looking for help, but

  • 0

Hey. You may have recently seen a post by me looking for help, but I did it wrong before, so I am going to start fresh and begin at the basics.

I am trying to read a text file that looks like this:

FTFFFTTFFTFT
3054 FTFFFTTFFTFT
4674 FTFTFFTTTFTF
… etc

What I need to do is put the first line into a String as the answer key.

Next, I need to create an array with the student ID (the first numbers).
Then, I need to create an array that is parallel to the student ID that contains the student’s answers.

Below is my code, and I can’t quite figure out how to get it to work like this, and I was wondering if someone could help me out with it.

public static String[] getData() throws IOException {
      int[] studentID = new int[50];
      String[] studentAnswers = new String[50];
      int total = 0;

      String line = reader.readLine();
      strTkn = new StringTokenizer(line);
      String answerKey = strTkn.nextToken();

      while(line != null) {
        studentID[total] = Integer.parseInt(strTkn.nextToken());
        studentAnswers[total] = strTkn.nextToken();
        total++;
      }
    return studentAnswers;
    }

So at the end of the day, the array structure should look like:

studentID[0] = 3054
studentID[1] = 4674
… etc

studentAnswers[0] = FTFFFTTFFTFT
studentAnswers[1] = FTFTFFTTTFTF

Thanks 🙂

  • 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-13T15:57:03+00:00Added an answer on May 13, 2026 at 3:57 pm

    Assuming you have opened the file correctly for reading (because I can’t see how the reader variable is initialized or the type of the reader) and the contents of the file are well-formed (according to what you expect), you have to do the following:

      String line = reader.readLine();
      String answerKey = line;
      StringTokenizer tokens;
      while((line = reader.readLine()) != null) {
        tokens = new StringTokenizer(line);
        studentID[total] = Integer.parseInt(tokens.nextToken());
        studentAnswers[total] = tokens.nextToken();
        total++;
      }
    

    Of course it would be best if you add some checks in order to avoid runtime errors (in case the contents of the file are not correct), e.g. try-catch clause around Integer.parseInt() (might throw NumberFormatException).

    EDIT: I just notice in your title that you want to use StringTokenizer, so I edited my code (replaced the split method with the StringTokenizer).

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

Sidebar

Related Questions

Hey this may sound simple but it escapes me, I have a list of
Recently I have been looking at jquery/javascript solutions to emulating the placeholder attribute, but
Hey all, title may be abit misleading but i didnt know the correct way
Hey there everyone. I have recently begun tweaking the new default wp theme, twenty
hey guys, i have read This post, so what i got is JSON is
Hey all, I'm learning Doctrine + Symfony and I may have chosen too complex
Hey guys sorry to ask but i need help with this query please I've
Hey peoples, I've been studying Java for a couple of weeks, and have decided
Hey right now I'm using jQuery and I have some global variables to hold
Hey folks, I have a field within a table that I need to do

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.