Sudoku Is Not Working For Few Inputs

Apr 22, 2015

The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value). My assignment is to get a solved sudoku for these values:

//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}

My current code

public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on

[Code] .....

View Replies


ADVERTISEMENT

Multiple Key Inputs Not Working

Sep 16, 2014

i am currently making a game in java and currently i am working on the basic mechanics. most of it is working fine but i cannot seem to make it so when the user presses and movment key and space to fire a bullet the bullet fires in the direction they are moving. here is the code i have for movement.

public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
int bulletx = Player.x + 100;
int bullety = Player.y + 20;
int key = e.getKeyCode();
if( key == e.VK_W){
p.moveUp();
}
if(key == e.VK_S){
p.moveDown();

[code]....

View Replies View Related

Sudoku Solver Backtracking Algorithm

Dec 5, 2014

It's about a backtracking algorithm trying to solve a sudoku, represented by an array of integer arrays. For testing matters, the start field is empty.

static boolean solve(int[][] field, int i, int j) {
if (filled(field)) {
return legal(field);
} else {
for (int k = 1; k <= 9; k++) {
field[i][j] = k;

[Code] ....

View Replies View Related

How To Write Mini Sudoku In 4x4 Puzzle Using Java

Oct 31, 2014

How to write a mini sudoku in 4x4 puzzle using java The entries of each grid are 1,2,3 or 4 only.

No number will be the on a row.

No number will be the same in a column.

There are 4 regions in the puzzle and no number will be the same in a region.

I want to ask how to finish the below code, because I don't know how to extend using the below code

import java.util.*; 
public class MiniSudoku {
 final static int SIZE=4;

[Code]....

View Replies View Related

Sudoku Checker Program - Cannot Find Symbol

Jul 9, 2014

I can't get the code to compile for the driver every time i get an error message saying

SudokuCheckerTest.java:28: error: cannot find symbol
foo.displayGrid(grid);
^
symbol: variable grid
location: class SudokuCheckerTest
SudokuCheckerTest.java:29: error: cannot find symbol
foo.getGrid(grid);

[Code] .....

4 errors

Java Code :

import java.util.Scanner;
public class SudokuChecker{
public SudokuChecker(){
// displays intro code and initializes the array grid as well as using method calls.
Scanner in = new Scanner(System.in);
int [][] grid = new int [4][4];
displayGrid(grid);

[Code] ....

View Replies View Related

Sudoku Solver - Scanner Isn't Functioning Properly

Nov 19, 2014

I am working on a program that should take an input file as a command line argument and check if that file contains a valid sudoku solution. Right now the main error I am getting is my scanner isn't functioning properly and is throwing inputMismatchexceptions, but Im also not sure about the validity of my functions, and i cannot test them because my scanner isn't working.

import java.util.Scanner;
 
//This class will read in a possible sudoku solution and test it for validity. If it is invalid, return at least one reason why.

public class SudokuVerifier {
//this function checks a row to see if it contains the numbers 1-9
public static boolean checkRow(int sudoku[][], int i) {
boolean contains=false; // keeps track if the line contains a certain number
for(int k=1; k<=9; k++) { //goes through every number from 1 to 9
for(int j=1; j<sudoku[i].length; j++) { //checks every element in the row to see if it is equal to k

[code]...

View Replies View Related

Sudoku - When Place Numbers More Than 4 At Random Places It Stops Responding

Apr 22, 2015

The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value).

My assignment is to get a solved sudoku for these values:

//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}

My Current code

public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on
public static void main(String[] args) {

[Code] ....

View Replies View Related

Sudoku GUI - How To Make Some Textboxes JDialogs Displaying Uneditable Numbers

Apr 25, 2014

So here is what i have so far for my sudoku game. Now my grid only displays textboxes where a user can input numbers but nothing will happen yet. I want to know how to make it so that the user can only input one character and only numbers. i would also like to know how to make some textboxes jdialogs displaying uneditable numbers that im taking from a sudoku website for the puzzle.

Main Class

import javax.swing.JOptionPane;  
public class Game{
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "Hello. Welcome to a game of Sudoku by Ezra Zike.");
Level select = new Level();

[Code] .....

View Replies View Related

Project Is Working On JFrame - But Not Working On JApplet

Apr 10, 2014

I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,

1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.

2) The problem may be to display the JDesktopPane or JInternalFrame.

My working Server Code extends withe JFrame..Java Code:

package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

[code]....

View Replies View Related

Displaying Inputs To TXT File?

Oct 13, 2014

so far this is what i have written. The program works correctly but I need to be able to have the numbers i am entering to show up on the .txt file.

import java.util.Scanner;
import java.io.*;
public class LargestAndSmallest {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);

[code].....

View Replies View Related

Modifying Files Using Inputs From GUI

Feb 25, 2015

I want to work on a project in which I have a GUI where I can choose certain variables from drop down menus. I want to use these variables to modify a few configuration files. I have looked upon internet for a few methods which can be used for the same. However, I am not sure about the method I should use. The files I want to modify consist of 10 -15 lines.

View Replies View Related

Using User Inputs In Other Class?

Feb 8, 2014

I have a LoginScreen class and one other class in my project. I want use user inputs (Username And Password) on other class if users details is true. I am stcuk at this point because when user attempt to Login connection is succesfully and other frame is coming to screen but i can reach user details anymore. Let me explain with codes;

LoginScreen class

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package deneme3;
import java.sql.Connection;

[code]....

You can see Button Action in MainProgramWindow " System.out.println( ??? );" How i can retrieve users inputs from this class ?

View Replies View Related

Calculations On Text Box Inputs

Mar 7, 2014

I have made a simple form, it consists of 3 text box's textbox1, textbox2 and textbox3 as well as 1 button button1. What I want to be able to do is put numbers into textbox 1 and 2 and then show the multiplication of these numbers in textbox 3 when the button is pressed and I was wondering what is the standard way of reading these numbers from the text box and allowing us to do the conversion obviously in the textbox its a string and we need to convert to an int or double or whatever to be able to perform calculations on them then convert it back into a string to display in text box 3?

View Replies View Related

Exceptions For Multiple Inputs

Oct 29, 2014

I'm writing a program that accepts three doubles from the user, and performs calculations on them. I want to be able to handle input mismatch exceptions on each individually (i.e., if the user enters a double for the first, then a letter for the second, I'd like to be able to keep the value entered for the first, and only require that the user try again with the second, then the third, etc.)... I tried putting each input instance into its own try/catch blocks, but it always goes back to #1 when an invalid input is entered. Right now, I have all three in one try/catch:

Java Code:

package com.itse2317;
import java.util.Scanner;
import java.util.InputMismatchException;
class Triangle
{
public static double side1 = 0.0, side2 = 0.0, side3 = 0.0;

[code]...

View Replies View Related

LWJGL Keyboard Inputs Not Recognized

May 10, 2014

I wanted to create a simple window with the LWJGL and a key input request which closes the window.I also wanted to create the classes in seperated packages, so it's more organized.The window displays but if I press that certain key nothing happens.Here is the Main class:

package bb.main;
import bb.input.Input;
import bb.main.render.SimpleRenderer;
public class Main {
public static void main(String[] args){
SimpleRenderer createWindow = new SimpleRenderer();
Inputinput= new Input();

[code]....

View Replies View Related

Reading Inputs Using Buffered Reader

Oct 13, 2014

I am trying to read the following input (which will be inputted by the user when run) using the BufferedReader approach:

1
*** * * * *** *** *** ***
* * * * * * * * *
* * * *** *** *** *** ***
* * * * * * * * *
*** * * *** *** *** ***

I am reading each line of the input one line at a time and incrementally storing four char positions into an array, so i am able to hold a vertical representation of each column. I.e. column 1 will be stored in array[0].

The problem with my code is that is does not read the last line of the input, it reads all the other inputs before it but just refuses to read the last line and execute the procedure of storing the characters.

Code:

public void defuseBomb(){
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String asciiLine = reader.readLine()+ " ";
int digit = (asciiLine.length())/4;
 
[Code] .....

View Replies View Related

Increasing Counter When User Inputs C / D Or E

Feb 15, 2015

We are writing our own classes and methods. My instructor has provide the code

/*-------------------------------------------------------------------------
import java.util.*;
public class Assignment5 {
public static void main (String[] args) {

[Code].....

I am having trouble with the question counter. I need the counter to increase when c, d or e are entered. I think I need to set up a if or while loop but I'm not sure how to setup the variables. This is what I have for the counter so far.

[public int getNumberOfQuestions(){
numQuestions = 0;
numQuestions ++;
return numQuestions;
}

View Replies View Related

Filling Array With Three Of User Inputs

Aug 9, 2014

I realized that I was not filling the array with anything but now I'm having issues filling it correctly. It's only filling the array with three of the user inputs ....

import java.util.Scanner;
public class DriverSort {
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
Sorter sorter = new Sorter();
int choice; // variable which says which sorting algorithm to use

[Code] .....

View Replies View Related

Lock Keyboard And Mouse Inputs

Mar 10, 2014

Which methods can be used to lock keyboard and mouse inputs using java??

View Replies View Related

While Loop Loops Forever Even With The Right Inputs

Sep 9, 2014

Why when the user enters Y or N, this loop still continues looping instead of quitting?

System.out.println("Enter Y to indicate Up OR N to indicate Down " + "
");
String option = scanner.nextLine();
 while (!response.equalsIgnoreCase("Y")||(!response.equalsIgnoreCase("N"))) {
System.out.println("Enter Y to indicate Up OR N to indicate Down " + "
");
option = scanner.nextLine();
}

View Replies View Related

Storing Multiple User Inputs In Array

Feb 28, 2015

I need to generate a league table in Java based on results provided in the shape of user input. I have the 6 teams in an array. I need to ask the user how many wins, draws, losses each team has had.

for (String element : teams) {
System.out.println(
"Please enter the number of wins, draws and losses for " + element);
int[] wins = new int [6];
int[] draws = new int [6];
int[] losses = new int [6];
}

How do I pull 3 separate values from the user and then store each value in a separate element of each array? so if one team wins 3, draws 2 and loses 1 - I need to put 3 into the wins array, 2 into the draws array and 1 into the losses array? I then need to total all this in a table.

View Replies View Related

Anomaly While Using Scanner Class For Taking Inputs

Feb 1, 2015

There is a problem that I am facing while using the Scanner class for taking inputs from the user. Suppose if I need to take an integer and a String input from the user, and I take the integer input first then the place where the user has to input the String skips and the variable shows a "" nothing on printing it. Suppose in this code snippet

import java.util.Scanner;
public class Test
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number");
int n = sc.nextInt();
System.out.println("Enter a word");
String str = sc.nextLine();
System.out.println("Enter integer is " + n);
System.out.println("Entered statement is " + str);
}
}

The output is
Enter a number
13
Enter a word
Enter integer is 13
Entered statement is

I need to know why this happens and how should I avoid it. I've seen that taking the String input first solves the issue but while taking the input in a loop to populate a database the program only lets the user enter the first statement and the following statements are skipped.

View Replies View Related

Return A String That Holds User Inputs

Apr 18, 2015

I'm working on an assignment for my Java Programming class that requires me to work with Multiple Classes.

Overview of the assignment: Create a "Database" that allows a user to input information about a College Class.

My program has three Classes:

The information that must be tracked in the Course Class is:
- Section Number
- Instructor
- Classroom
- Students (an ArrayList of class Student)

The information that must be tracked in the Student Class is:
- Name
- Major
- GPA
- Hours

The Driver class will use the main method to print the user a prompt asking for inputs, then display all of the user's inputs after he/she wished to exit the program.

I'm having no trouble with asking the user for inputs and then checking the validations for the inputs, I'm currently struggling with return a String that houses all of the user's inputs for the variables above. The information must be returned in a method called toString(). Both the Student and Course Class must have a toString() method that returns the information in the class (value of the variables), I must then call upon these methods from the main method of the Driver Class to print them back to the user.

The toString methods within the Student & Course Classes are at the bottom of the code

To Summarize: What I need to do within the toString() methods to return the values the user has inputted for the various variables? Such as.. Should I pass something through the method? Do I need the this keyboard to pass through the variable again? I just fear that I'm currently misunderstanding a very critical part of programming.

My Driver Class

import java.util.Scanner;
public class Driver {
Course courseInputs = new Course();
Student studentInputs = new Student();
public static void main(String[] args) {

[Code] .....

View Replies View Related

Need To Count Strings That How Many Inputs From User Were Numbers

Jan 30, 2014

import java.util.Scanner;
public class CountStringNumbers { // show the number of Strings that were numbers . . ..
public static void main(String []args){
int count = 0;
int countNumbers=0;
Scanner input=new Scanner(System.in);

[code]...

can count the numbers from 0-9 if the user puted but if it is 10 it doesnt count it , and i need to write all the numbers to have that option. . . . Is there an easy way that includes all the numbers? like if(word.equals(number)){<<<???? (numbers) i know htat doesnt work but is there anything similar ?? ??

countNumbers++;
}
System.out.println("Type Something , , , and to end the the termination type STOP");
word=input.nextLine();
count++;
}
System.out.println("You wrote "+count+" lines wich from those lines "+countNumbers+" were numbers and the programe terminated ");
}
}

View Replies View Related

Write A Program Where User Inputs A Month Between 1-12

Sep 21, 2014

I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:

insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java

The code:

import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");

[code].....

I think I have just forgot to put in a few { } symbols, maybe an open loop?

View Replies View Related

Developing A Program That Inputs Telephone Numbers

Jan 26, 2014

Develop an algorithm for a Java program that takes as input a single letter and displays the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way:

2 = ABC 3 = DEF 4 = GHI 5 = JK 6 = MNO 7 = PQRS 8 = TUV 9 = WXYZ

The screen dialog might look like this: Enter a single letter, and I will tell you what the corresponding digit is on the telephone. R The digit 7 corresponds to the letter R on the telephone.

The program should display a message indicating that there is no matching digit for any non-alphabetic character entered by the user. Also, the application should recognize only uppercase letters. If a user enters a lowercase letter, the program should display an error message. Prompt the user with an informative message for the input value as shown above.

The application should include the input letter as part of the output.

Write the algorithm to solve this problem including steps for prompting the user, getting input from the keyboard, and displaying the results.

Write the Java program that you designed, using your algorithm as a guide. Use your algorithm as comments in the body of the main method.

Use proper indentation, and meaningful identifiers throughout the code.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved