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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:49:10+00:00 2026-06-14T23:49:10+00:00

This is a long one. I have a very odd problem. I need to

  • 0

This is a long one.

I have a very odd problem. I need to read two matrices from a text file, multiply them together, and then print out the result. That’s all very easy. The problem is that the file containing the matrices looks like this:

1 2 1 2 3
3 4 4 5 6
5 6
7 8

How this crazy thing works is as follows (just for reference, you can skip this part):

  1. Read down the first column. Once you hit whitespace OR the end of the file you have the number of rows in your FIRST matrix.

  2. Count the number of integers per row, row-by-row. Once that count drops the you know how many rows your second matrix has. IF the first matrix was “shorter” than the file, then this step is unecessary, as the second will simply be the number of rows in the file.

  3. Since multiplication requires matrix one’s column count to be the same as matrix two’s row count ( [3×6 * 6×4] is valid, [3×6 * 5×4] is not) then by knowing the number of columns in matrix one we can find the number of rows in matrix two, and vice-versa.

I need to find either value.

So from that file matrix one would be

1 2
3 4
5 6
7 8

and two is

1 2 3
4 5 6

So you’d think you could just count the rows in column one and the number of columns in the last row to find everything, but sometimes the file looks like this:

1 2 1 2 3
3 4 4 5 6
      7 8

So I just need some conditional juggling depending on whether the bottom left corner is an int or whitespace. I’m thinking reading the whole file into a 2D Array and manipulating from there.

So here are my formal questions:

I need to read in every character of the file individually, whether it be int or whitespace, so I can build a faithful Array[][]. What is the best method of doing that? I have tried Scanner, StringTokenizer, FileInputStream, BufferedInputStream, Reader, and FileReader but none of them give me a simple char by char.

Secondly, any suggestions on splitting the matrices from the unified Array[][] into two smaller Array[][]s?

  • 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-14T23:49:11+00:00Added an answer on June 14, 2026 at 11:49 pm

    You should be able to read in the file character by character with a FileInputStream.

    Please note that the read() method returns -1 at EOF. Otherwise cast the returned value to a char.

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

Sidebar

Related Questions

I have very long xml file, like this: <cars> <car> <name>Ford</name> <number>F33</number> <color>Blue</color> </car>
I got a very long telephone log as a text file and I have
I have one very large text file(27GB) that I am attempting to make smaller
I have been banging my head on this one for too long. I have
This is a very odd problem and I'm sorry in advance about the title
I have very simple problem that I can't solve. I need to do something
OK ... this is gonna be a long one. I have a iPhone 4
I have one very long string. In it are markers and between those markers
this post is a long one sorry for that but the problem is complex
I've never seen this happen before, very odd. I have a local SQL Server

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.