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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:32:56+00:00 2026-05-25T21:32:56+00:00

So I’m having a bit of an issue with my code. My objective is

  • 0

So I’m having a bit of an issue with my code. My objective is to take an adjacency matrix from a file and input it into a 2d array. I was able to do that. Now I’m using the data structure for Breadth First Search and Nodes to work with that array.

Right now, I’m trying to simply create new Nodes, but I cannot make nodes due to being a char. Here let me post my full code. I’ll post the error below.


package javaapplication1;
import java.io.*;
import java.util.*;
import tio.*;
import java.lang.*;



public class JavaApplication1 {
    private static int row = 0;
    private static int col = 0;
    private static int n = 20;
    private static int[][]adjMatrix = new int[n][n];


public static int[][] adjMatrix() throws FileNotFoundException, IOException{
   //int n = 20;
   //int row = 0;
   //int col = 0;
   //int[][]adjMatrix = new int[n][n];
   String file =   ("C:\\Users\\David\\Documents\\NetBeansProjects\\JavaApplication1\\src\\javaapplication1\\adjmatrix.txt");

   BufferedReader in = new BufferedReader(new FileReader(file));
   String line;
   //System.out.println(in.readLine());


   int k = 0;
     while ((line = in.readLine()) != null){
         //System.out.println(row);
         String[] temp = line.split("\\s+");
        for(col = 0; col < adjMatrix[row].length; col++){
           adjMatrix[row][col] = Integer.parseInt(temp[col]);
          // System.out.println(" " + temp[col] + " " + col);
        }
row++;
     }  //end while
   //System.out.print(array[4][1]);
   in.close();
   return adjMatrix;



} // endclass
 public static void main(String[] args)
    throws IOException{
    adjMatrix();
    // Create the nodes (20 based off adj matrix given
    Node nA =new Node('1');
    Node nB =new Node('2');
    Node nC = new Node('3');
    Node nD = new Node('4'); 
    Node nE = new Node('5');
    Node nF=new Node('6');
    Node nG=new Node('7');
    Node nH=new Node('8');
    Node nI=new Node('9');
    Node nJ=new Node('10');
    Node nK=new Node('11');
    Node nL=new Node('12');
    Node nM=new Node('13');
    Node nN=new Node('14');
    Node nO=new Node('15');
    Node nP=new Node('16');
    Node nQ=new Node('17');
    Node nR=new Node('18');
    Node nS=new Node('19');
    Node nT=new Node('20');


    // Create a graph, adding the nodes, and creating edges

    Graph g = new Graph();
    for (int i=1;i<=20;i++){
        String aString = Integer.toString(i);
        aString = n+aString;
        g.addNode(aString);
    }
//        g.addNode(nA);
//        g.addNode(nB);
//        g.addNode(nC);
//        g.addNode(nD);
//        g.addNode(nE);
//        g.addNode(nF);
//        g.addNode(nG);
//        g.addNode(nH);
//        g.addNode(nI);
//        g.addNode(nJ);
//        g.addNode(nK);
//        g.addNode(nL);
//        g.addNode(nM);
//        g.addNode(nN);
//        g.addNode(nO);
//        g.addNode(nP);
//        g.addNode(nQ);
//        g.addNode(nR);
//        g.addNode(nS);
//        g.addNode(nT);
//        g.addNode(nU);
//        g.setRootNode(nA); 

//        g.connectNode(nA,nB);
//        g.connectNode(nA,nD);
//        g.connectNode(nA,nE);
//        g.connectNode(nA,nF);
//        g.connectNode(nA,nG);
//        
//        g.connectNode(nB,nE);
//        g.connectNode(nB,nF);
//        g.connectNode(nB,nG);
//        
//        g.connectNode(nC, nD);
//        g.connectNode(nC,nE);
//        g.connectNode(nC,nF);
//        g.connectNode(nC,nG);
//        
//        g.connectNode(nD,nE);
//        g.connectNode(nD,nF);
//        
//        g.connectNode(nE, nF);
//        g.connectNode(nE,nG);
//        
//        g.connectNode(nF,nG);
//        
//        g.connectNode(nH, nI);
//        g.connectNode(nH,nJ);
//        g.connectNode(nH,nK);

//        g.connectNode(nI,nJ);
//        g.connectNode(nI,nK);
//        g.connectNode(nI,nL);




     g.bfs();


  } // end main
} // end class

I know that is a lot of code, but that is the reason why I would really like to not brute force the g.connectNode and the g.addNode. Anyways I can implement a loop for this?
Also, when I start doing “Node nJ=new Node(’10’);” it gives me errors since my Node is a char, any suggestions on bypassing that without breaking everything? The error is an unclosed character literal.

Here is the code for node.

public class Node {
    public char label;
    public boolean visited=false;
    public Node(char l)
    {
            this.label=l;
    }
}

Thank you for your help, and let me know if I need to edit or add anything.

  • 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-25T21:32:57+00:00Added an answer on May 25, 2026 at 9:32 pm

    First suggestion: put your nodes in an array or list, don’t repeat the same thing 20 times.

    Change your label’s data type to String, and everything will be fine.

    I am not sure how you define your Graph class. But you should really define your addNode method as

    bool addNode(Node n) or something like that.

    Another thing is to keep your data field private and provide getters and setters.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.