Can somebody please help me with a java assignment please

i know this is a long shot asking people on Sup Forums for help but i'm desperate.

I'm trying to create a sudoku checker, this is my third project trying to do this now. This is what i've done so far,

public class SudokuVerifier
{
//* Turns the sudoku board into a puzzle

private int[][] board;
{

this.board = board;

}

/*checks if each box in the sudoku puzzle is 1-9
* if it's false it returns -5
* if true it returns 0
*
*/

public int verify(String candidateSolution)
{
for (int i = 0; i < 9;i++)

{
for(int j = 0; j < 9;j++)
{
if(board[i][j] > 9 || board[i][j] < 1)
{
return -5;
}
}
}


return 0;
}
the board variable is basically the 9 by 9 numbers in a sudoku puzzle. if the number on the puzzle is greater than 9 it returns -5 (meaning it's wrong) and if it's less than 1 it returns -5. and if the solution is correct it returns 0 (meaning no errors). That's basically what i'm trying to do, but i don't know how to assign the [9] [9] to it without it getting messed up. And i'm also not to sure how to do the rows, columns and the 3x3 grid as well, because i'm not too sure how to create their variables, do i use the board variable to do it? If someone could please help me with this it would be much appreciated. i've been trying to do this for the past day now and this is my 3rd attempt.

Honestly you're better off going to Reddit or StackOverflow.
This place will just shit on you for not using their personal flavor of programming language.

We would help you more by refusing to do your homework for you

i'm not asking you to do it for me, i just need a point the right direction. Please, i already have the vague idea on what to do, i just need help with assigning the rows and variables

any sub reddit that are active?

Why assign rows and variables? You already have everything you need. Better go read about two dimensional arrays and stop copy pasting from da stak.

> i've been trying to do this for the past day now and this is my 3rd attempt
Kys worthless piece of shit.
No really if you want to have a fullfilling life you should try and get a job at McDonald's. That's something worth of your intelligence.

>returns -5
kill yourself

Drop out of whatever shitty course is making you do this and read HtDP or SICP

which do you suggest and why? from what I read, HtDP is a bit more entry level, but fundamentally covers similar topics...

Is it a waste of time to read both?

?
?
I don't fucking know. Half the people here don't go on reddit, and the other half would never tell you they do.

Jesus dude, not called for.
Everyone has goes through a period where they're still beginners.
You can't know everything at once, he just needs to practice. Don't insult others just because your insecure.

I can't help you, but you could've avoided some of the 'kys'...

first off, don't start off with "people on Sup Forums", this is a cringeworthy flag that you are a newfag, secondly, try and post this questions on /sqt/...

>people are unironically discussing Reddit now

[ code ] tags [ / code ]
o
d
e
]
tags

>and the other half would never tell you they do.
lol so hard

>Being loyal to a particular site with many very different communities
>Being this much of a cuck

kysasap

>why don't you do my homework for me???? This place is bullshit I' going and I'm never coming back I'M SERIOUS!!!!

First of all. Choose better names.
You are making a class for a soduko board, the verification is just a function that relates to the board.
I assume you are going to solve the soduko board sometime during the class, so you might start with that assumption.
Say you have an easy board, you can solve it through verification:
Each field on the board contains 9 options.
By running verify, you can reduce the options so there isn't a number in the same row, same column or same 3x3 square.
either your verification should check if it is valid or it should reduce the options as well.
Therefore, I would make the board 3 dimensional if you want to solve it as well.

Now as for your function, you return an int for no good reason. You even have to explain what the values mean, it is a very bad model to use if the only outcome is true or false.
This leads us back to the naming of the function.
"verify" isn't really a question that you can answer with true or false.
If you choose a name like "isValid", there wouldn't be any confusion.
As for the functionality, checking whether the numbers are within 1-9 (INCLUDING, not EXCLUDING) is not the point of a soduko.
You need to check if the numbers are unique.

Make a few test boards to see if your function works.

People with this attitude deserve to work in Mickey dees. Unless your black or a minority you won't get hired unless you shut up and put the work in

>returns -5
-1 is the generally accepted sentinel value. -5 will work fine too, but it's bad practice to use a random number of your choice here. Stick to -1. Or better yet have verify() return a boolean true or false instead.

I'm going to move forward under the assumption that "Sudoku checker" means you're trying to validate that this.board is a valid solved Sudoku puzzle

>i don't know how to assign the [9] [9] to it without it getting messed up
Not sure what you mean by this. You don't know how to define the values in the board array?

>because i'm not too sure how to create their variables
You can use board like you are now. You'll also need a variable to track the sum of the numbers in the row/column/sub-grid to ensure they add up to 45 (1+2+...+9). Think about how you would modify your for loops so that you only check the first 3x3 section of the grid, adding the value you find at boards[i][j] each time, then comparing the total to 45.

It's easy. Just make sure that the sum of each row is 1+2+...+9, and also, each sub-square has also the sum 1+2+...+9. If these conditions are met, return True, else return False.

private boolean checkSudokuStatus(int[][] grid) {
for (int i = 0; i < 9; i++) {

int[] row = new int[9];
int[] square = new int[9];
int[] column = grid[i].clone();

for (int j = 0; j < 9; j ++) {
row[j] = grid[j][i];
square[j] = grid[(i / 3) * 3 + j / 3][i * 3 % 9 + j % 3];
}
if (!(validate(column) && validate(row) && validate(square)))
return false;
}
return true;
}

private boolean validate(int[] check) {
int i = 0;
Arrays.sort(check);
for (int number : check) {
if (number != ++i)
return false;
}
return true;
}

what are you stuck on?

if you need a algorithm to put some numbers in the 3x3, i did row*3 + column.

The thing with HtDP is it takes you through a set of DSLs that incrementally introduce you to features of Racket (aka PLT Scheme) instead of dumping the whole language on you at once. That and it's written in plainer language. And no, it's absolutely not a waste of time to read both books.

It's funny how the same thing that makes java good for big projects is a nuisance for little pet codes / learning the language

a type error?
> board is int[][]
> candiSol is String?

how to check for valid !9 permutations?
> int arr[10] = 0's
> loop
> arr[val] = arr[val] + 1;
> loop
> arr[val] == 1;