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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:27:38+00:00 2026-05-21T17:27:38+00:00

I want to load the initial positions of two robots in a bidimensional array,

  • 0

I want to load the initial positions of two robots in a bidimensional array, they are indicated by the letters N,S,O,E.

The following code ain’t working. Why?

static Point[] robotInitialPositions(char [][]inputMatrix){

     Point [] helperArray = new Point[2];

     int aux=0;

     for (int i=0; i<(inputMatrix[0].length-1); i++)
         for (int j=0; j<(inputMatrix[0].length-1); j++)
         {
            if((inputMatrix[i][j]=='N')||(inputMatrix[i][j]=='S')||(inputMatrix[i][j]=='O')||(inputMatrix[i][j]=='E'))
            {
                    helperArray[aux++]= new Point(i,j);                 
            }

         }

     System.out.println("helper array 1: i,j " + helperArray[1].i + ", " + helperArray[1].j);
     //NullPointerException here 
     return helperArray;

 }

Full code:

package bfs_robots;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

class Point {

    int i;
    int j;

    Point(int i, int j){
        this.i=i;
        this.j=j;
    }

}

public class Main {




 static char turnCounter (char orientation){

     if(orientation=='N')
         return 'O';
     if(orientation=='O')
         return 'S';
     if (orientation=='S')
         return 'E';
     else
         return 'N';

 }

 static char turnClock(char orientation){

      if(orientation=='N')
         return 'E';
     if(orientation=='E')
         return 'S';
     if (orientation=='S')
         return 'O';
     else
         return 'N';

 }

 static Point[] robotInitialPositions(char [][]inputMatrix){

     Point [] helperArray = new Point[2];

     int aux=0;

     for (int i=0; i<(inputMatrix[0].length-1); i++)
         for (int j=0; j<(inputMatrix[0].length-1); j++)
         {
            if((inputMatrix[i][j]=='N')||(inputMatrix[i][j]=='S')||(inputMatrix[i][j]=='O')||(inputMatrix[i][j]=='E'))
            {
                    helperArray[aux++]= new Point(i,j);                 
            }

         }

     System.out.println("helper array 1: i,j " + helperArray[1].i + ", " + helperArray[1].j);

     return helperArray;

 }



static void bfs_find_solution (char[][] inputMatrix){


    int countOfMovements=0;
    //  each turn and displacement adds one

    //  when moved N,S,D and O must be replaced with .
    // * indicates wall, invalid movement

    Point robotInitial[] = robotInitialPositions(inputMatrix);





}









    public static void main(String[] args) throws IOException {


        BufferedReader br = new BufferedReader(new FileReader(new File("input.txt")));

        char [][] inputMatrix;

        String line;
        char [] lineAsCharArray;
        int matrixSize;

        while(true){

            line = br.readLine();
            matrixSize=Integer.parseInt(line);

            inputMatrix = new char [matrixSize][matrixSize];

            if (matrixSize==0){  // end outer looping
                break;
            }

            else { //begin inner looping

                for (int i=0; i<matrixSize; i++){

                    line = br.readLine();
                    inputMatrix[i] =line.toCharArray();

                }

                bfs_find_solution(inputMatrix);
            }


        }

    }

}

input.txt (0 indicates the end of file)

5
D....
N...S
.....
*...*
....D
5
.....
S..S.
.....
.....
D..D.
3
SN.
***
.DD
0
  • 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-21T17:27:39+00:00Added an answer on May 21, 2026 at 5:27 pm
         for (int i=0; i<(inputMatrix[0].length-1); i++)         
             for (int j=0; j<(inputMatrix[0].length-1); j++)
    

    Seems wrong.
    The first line should be inputMatrix.length-1

    Also the “<” should be “<=” I think. Or keep the “<” and don’t have the “length-1”, instead just “length”

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

Sidebar

Related Questions

I'm working on a project in C# w/ XNA, and I want to reorganize
I want the messagebox to only show if the number is equal to 0.
I want to use a temp directory that will be unique to this build.
I want to get the header of a selected tab-item of a tab-control and
I want to have generalised email templates. Currently I have multiple email templates with
Every time that I want to do a Layout, I'm getting a black layout
If all tables I want to delete from have the column gamer_id can i
I'm in the process of porting some code from Linux to Mac OS X.
I'm trying to build a Chrome browser extension, that should enhance the way the
I am using a 3rd-party rotator object, which is providing a smooth, random rotation

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.