Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Reducing A Matrix Into A Reduced Row Echelon Form

 
Ranch Hand
Posts: 130
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am currently working on a project from JetBrains Academy which requires me to read a file containing a matrix and reduce it into reduced row echelon form.
The project requirement can be found here https://hyperskill.org/projects/40/stages/211/implement

This is my current implementation, it only reads the file into two dimensional integer array.

Any recommendations to make the current implementation robust will be appreciated.



This how the content of the file looks like
The first line determines the row length of the matrix
3
1 1 2 9
2 4 -3 1
3 6 -5 0

Thank you.
 
Marshal
Posts: 15565
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have used a Scanner and Scanner.nextInt() to eliminate the need to do readLine.split() and Integer.parseInt()--that's just too much hoop-jumping for my taste.
 
Saloon Keeper
Posts: 3919
154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing wrong with your code, but I would use this:

The method Files.lines may throw an IOException, so either this code must run in a try/catch block, or the method must be declared to throw such an Exception.
 
Piet Souris
Saloon Keeper
Posts: 3919
154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops... when writing the above code I started from a wrong example. Sorry. I meant this code:
 
Kelvin Okornoe
Ranch Hand
Posts: 130
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the suggestion so far, I have noted them.
Am still working on the program and I will be posting it here for more reviews.
Thank you.
 
We don't have time for this. We've gotta save the moon! Or check this out:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic