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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:23:41+00:00 2026-05-26T22:23:41+00:00

I have a problem with matrix. I have a matrix in txt file. This

  • 0

I have a problem with matrix. I have a matrix in txt file. This matrix looks:

231 324 123
345 565 234
657 234 654

I want to replacement elements to form:

654 234 657
234 565 345
231 324 123

I have a algorithm with replacement elements: 3-1-i, where i is number of choosen element from array. I have a problem how I read file and save elements to array and how implement this loop. This is my try with reading txt file and saving elements to array:

    List<String[]> rows = new ArrayList<String[]>();
    while ((line = bfr.readLine()) != null) {
        String[] row = line.split(" ");
         rows.add(row);

       }
    System.out.println(rows.toString());  

But I get [Ljava.lang.String;@525483cd as result.
Can anyone help me with this loop and reading this matrix?

  • 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-26T22:23:42+00:00Added an answer on May 26, 2026 at 10:23 pm

    Note : I used String s with newline characters \n, works the same way if the string is gotten from a file.

    import java.io.*;
    import java.util.StringTokenizer;
    
    public class file {
    public static void main(String args[]) throws IOException {
    
    String s = "231 324 123 \n 345 565 234 \n 657 234 654";
    
    StringTokenizer n = new StringTokenizer(s);
    String [] arr = new String[9];
    int nn = 0;
     while(n.hasMoreElements()){
        arr[nn] =  n.nextToken();
        nn+=1;
    }
    
    for(int iii = (arr.length -1); iii >=0 ; iii--){
       System.out.print(arr[iii] + "  ");
    
        if((iii % 3) == 0) {
            System.out.println();
        }
    }
    
    }
    
    
    
    }
    

    Output is

    654 234 657
    234 565 345
    123 324 231

    Edit To read the string from file

    public static void main(String args[]) throws IOException {
    
    int i;
    FileInputStream fin = new FileInputStream("files.txt");
    String n = "";
    
    do {
         i = fin.read();
         n += (char) i;
       } while(i != -1);
    
       fin.close();
    //String n now contains the contents of the file
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I've found a bunch of posts on this problem and have actually managed to
I have a problem with events stacking up. I've got a matrix of large
i have this problem when my Sprite rotation origin is fixed at top left
I have a problem with replacement elements in a matrix. I have a matrix
I have following problem: myvec <- c(1:3) mymat <- as.matrix(cbind(a = 6:15, b =
I have a problem with my matrix not rendering properly in HTML. It's a
I have this problem to solve that I have no idea how to do
I have one 2D matrix. My problem requires me to logically divide it into
I have some problem with matrix multiplication: I want to multiplicate for example a

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.