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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:53:42+00:00 2026-05-30T03:53:42+00:00

I’m scanning a text file that has a sudoku board with a few separators.

  • 0

I’m scanning a text file that has a sudoku board with a few separators. this is what a sample input would look like.

1 - - | 4 5 6 | - - -  
5 7 - | 1 3 b | 6 2 4  
4 9 6 | 8 7 2 | 1 5 3  
======+=======+======  
9 - - | - - - | 4 6 -  
6 4 1 | 2 9 7 | 8 3 -  
3 8 7 | 5 6 4 | 2 9 -  
======+=======+======     
7 - - | - - - | 5 4 8   
8 r 4 | 9 1 5 | 3 7 2   
2 3 5 | 7 4 $ | 9 1 6  

where it has “|” as borders and =====+====+==== as dividers. I made this code to ignore the | and ====+===+=== but it’s skipping that part of the code and declaring them as invalid characters and adding 0’s in there place

public static int [][] createBoard(Scanner input){

    int[][] nSudokuBoard = new int[9][9];

  for (rows = 0; rows < 9; rows++){

        for (columns = 0; columns < 9; columns++){

            if(input.hasNext()){

                if(input.hasNextInt()){
                    int number = input.nextInt();
                    nSudokuBoard[rows][columns] = number;
               }//end if int

                else if(input.hasNext("-")){
                    input.next();
                    nSudokuBoard[rows][columns] = 0;
                    System.out.print("Hyphen Found \n");
                    }//end if hyphen

                else if(input.hasNext("|")){
                    System.out.print("border found \n");
                    input.next();

                }// end if border
                else if(input.hasNext("======+=======+======")){
                    System.out.print("equal row found \n");
                    input.next();
                }// end if equal row

               else {
                   System.out.print("Invalid character detected at... \n Row: " + rows +" Column: " + columns +"\n");
                   System.out.print("Invalid character(s) replaced with a '0'. \n" );
                   input.next();
               }//end else

            }//end reading file
       }//end column for loop
    }//end row for looop
 return  nSudokuBoard;
}//end of createBoard

I talked it over with a tutor but i don’t remember his suggestion on how to fix this.

  • 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-30T03:53:44+00:00Added an answer on May 30, 2026 at 3:53 am

    Your loops increment the row and column counters even when you are consuming a border or a divider. So even after you fix other issues (as explained in the previous answer), you will finish filling the matrix before you’ve read all your input. You need to modify your code to conditionally advance the row and column counters only after you’ve consumed an integer or a dash. This would mean removing the for loops, changing the first if(input.hasNext()) to a while, and adding rows++ and columns++ in the places where you’ve consumed an integer or dash and are setting a value for nSudokuBoard[rows][columns]. You would also need logic to determine when to increment rows and when to set columns back to 0.

    Also, stylistically speaking, you should rename rows to row and columns to column.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
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
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.