Click here to Skip to main content
15,888,816 members
Home / Discussions / Java
   

Java

 
GeneralRe: programming Pin
quest4knowledge20-Dec-12 6:39
quest4knowledge20-Dec-12 6:39 
AnswerRe: programming Pin
April Fans19-Dec-12 16:40
April Fans19-Dec-12 16:40 
GeneralRe: programming Pin
Richard MacCutchan19-Dec-12 23:11
mveRichard MacCutchan19-Dec-12 23:11 
GeneralRe: programming Pin
quest4knowledge20-Dec-12 6:44
quest4knowledge20-Dec-12 6:44 
GeneralRe: programming Pin
April Fans27-Dec-12 3:54
April Fans27-Dec-12 3:54 
QuestionInfix to Prefix, Incorrect output Pin
SamuelSkenzy15-Dec-12 14:19
SamuelSkenzy15-Dec-12 14:19 
AnswerRe: Infix to Prefix, Incorrect output Pin
TorstenH.16-Dec-12 19:47
TorstenH.16-Dec-12 19:47 
QuestionProblem in scanning from file in Sudoku backtracking Pin
Member 858607213-Dec-12 22:10
Member 858607213-Dec-12 22:10 
Hello...I'm writing a sudoku project, which can solve a sudoku table with backtracking algortihm...but when I test the value of "matrix" array by debugging I see that these are not correct....can any body help me?
This is an example of input file :
3 0 0 9 0 0 2 0 0
0 0 5 0 0 0 0 0 7
6 0 0 0 3 0 0 0 8
0 0 0 0 6 1 0 4 0
0 4 0 0 0 0 7 0 0
0 3 6 0 0 0 0 9 0
0 2 7 0 0 0 0 0 0
0 0 0 0 1 0 8 0 5
0 9 0 2 0 8 0 0 0

Java
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package filesudoku;

/**
 *
 * @author ahangari
 */
import java.io.*;
import java.util.*;
import java.lang.Exception;


public class Sudoku {

     public static int[][] matrix;
     public static int counter = 0;
     public static String matrixView;

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

          System.out.print("Please enter file name: ");
          Scanner in = new Scanner(System.in);
          String fileName = in.next();
          matrixCreate(fileName);

        // TODO code application logic here
    }
 public static void matrixCreate(String fileName) throws FileNotFoundException {

    File getFile = new File(fileName);
    Scanner scan = new Scanner(getFile);
    matrixView = null;

    while (scan.hasNextLine()){
      matrixView = scan.nextLine();//consider each line of input as a string
      counter++;//for counting rows number
      System.out.println(matrixView);// printing in output
    }

    scan.close();

    matrix = new int[counter] [matrixView.length()];//an array for keeping the value of each col and row


    scan = new Scanner(getFile);
    char getCol;
    for (int rows = 0; rows < counter; rows++){
      matrixView = scan.nextLine();
      for (int cols = 0; cols < matrixView.length(); cols++){
        getCol = matrixView.charAt(cols);//
        matrix[rows] [cols] = getCol;//
      }
    }



 
  }

}

SuggestionRe: Problem in scanning from file in Sudoku backtracking Pin
Richard MacCutchan13-Dec-12 22:50
mveRichard MacCutchan13-Dec-12 22:50 
GeneralRe: Problem in scanning from file in Sudoku backtracking Pin
Member 858607213-Dec-12 23:17
Member 858607213-Dec-12 23:17 
GeneralRe: Problem in scanning from file in Sudoku backtracking Pin
Richard MacCutchan13-Dec-12 23:47
mveRichard MacCutchan13-Dec-12 23:47 
GeneralRe: Problem in scanning from file in Sudoku backtracking Pin
Member 858607214-Dec-12 0:30
Member 858607214-Dec-12 0:30 
QuestionHow can I get the use of a female's voice in Java Pin
Showlar13-Dec-12 6:30
Showlar13-Dec-12 6:30 
AnswerRe: How can I get the use of a female's voice in Java Pin
Richard MacCutchan13-Dec-12 7:37
mveRichard MacCutchan13-Dec-12 7:37 
AnswerRe: How can I get the use of a female's voice in Java Pin
TorstenH.16-Dec-12 19:50
TorstenH.16-Dec-12 19:50 
GeneralRe: How can I get the use of a female's voice in Java Pin
April Fans26-Dec-12 17:06
April Fans26-Dec-12 17:06 
Questionj2me Pin
4yee12-Dec-12 7:23
4yee12-Dec-12 7:23 
AnswerRe: j2me Pin
TorstenH.12-Dec-12 22:29
TorstenH.12-Dec-12 22:29 
SuggestionRe: j2me Pin
April Fans26-Dec-12 17:08
April Fans26-Dec-12 17:08 
Questionparse and validation in validation.txt Pin
duka_pa11-Dec-12 11:05
duka_pa11-Dec-12 11:05 
AnswerRe: parse and validation in validation.txt Pin
Richard MacCutchan11-Dec-12 11:16
mveRichard MacCutchan11-Dec-12 11:16 
Questionreading barcode Pin
junaid_ullah7-Dec-12 10:18
junaid_ullah7-Dec-12 10:18 
AnswerRe: reading barcode Pin
Richard MacCutchan7-Dec-12 22:07
mveRichard MacCutchan7-Dec-12 22:07 
GeneralRe: reading barcode Pin
junaid_ullah8-Dec-12 4:36
junaid_ullah8-Dec-12 4:36 
GeneralRe: reading barcode Pin
Richard MacCutchan8-Dec-12 22:23
mveRichard MacCutchan8-Dec-12 22:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.