Predrag Djindjic

Greenhorn
+ Follow
since Mar 10, 2019
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Predrag Djindjic

So basically i first had to make a method that creates int[][] with sudoku rows.Then i had to make 3 methonds that check if the given data for sudoku is valid.I made 1 method that checks rows(nested for loop that iterates through whole data and checks if there is equal numbers in every row), the 2nd method is the same just for the columns and the third checks if the number is the unique one in the 5x5 square.
4 years ago
This is not an argument.I just said read everything I wrote (and I wrote ant the end of an original post that my assignment is to check if it is valid), and then you said specify the problem you have.I really appreciate you commenting but again, if you just write "I think this is not correct" it really doesn't help.
Also in main method i give the argument(dadoteka) which contains the info im analyzing.
4 years ago
It's correct and yeah it verifies if it's true, as i wrote in the original post. As i said just please read everything i wrote before you comment on my post because it leads me to some totally different things.
4 years ago
Here is the code if anyone needs it:
4 years ago
Guys no offense, but almost everything you post is not helpful at all.I am asking you for help for an algorithm to solve subblocks in Sudoku, and i mention before that I already wrote rows and column check methods, and the thing you type is: you need a boolean method which returns boolean of all three checks.I literally typed that i did that prior to your reply.I dont want to be rude and i'm new on forum but if you want to comment and help me please read everything and don't just type the first thing that comes to your mind, try to reply something that can actually help me.
P.S. I did it, someone just had to link me some Sudoku solving algorithms on StackOverflow.
Have a great day
4 years ago
As you can see in the picture above, the sudoku is 25x25 fixed and the subblocks are 5x5 as in all the Sudoku tasks ever if you ever played it.Now i have to make a method to check if any number is repeating itself in it's block and im struggling with that.I found some solutions online but they are not helpful because all of them require the exact number i need to chect that for in parametac, but I have to check that for every number in given Sudoku list.If you can help me in any way,write it please.Thank you!
4 years ago
I've done the first part, which is making a table out of given data.Now i have table in this shape:
{8,3,4,4}
{3,2,4,1}
{2,3,5,6}
And now the second part is to check if the given data is true(by sudoku standard rules).The sudoku is 25x25 and i have to check all rows,columns and little 5x5 blocks for mistakes.I need help with that 5x5 little blocks in 25x25 sudoku.Check the picture above if you dont get what im saying.
Thanks for quick replies!
4 years ago
Hello guys! I Have a new task which im struggling with, so if you can help me, feel free to comment this post.
For Sudoku size 25, the same rules apply to standard Sudoku size 9: we enter numbers from 1 to 25 in the fields so that no row and no column have duplicate numbers. In addition, it must also be noted that the numbers are not repeated in any of the 25 smaller squares of 5 x 5 ( see picture below).

The Sudoku Puzzle solution is written in a text file, each line of 25 numbers in its line in the file (25 lines in the file). The numbers in the row are separated by one or more spaces. The example puzzle file is sudoku1.txt which has this shape:

 8 20 13 24 19  3 12  7 25 21 16  5  6 17  2  9 18 11 10  4 22  1 15 23 14
 9 22 21 10 17  4 13  5 24 18 12 20 19 11 15 14  1 16 25 23  6  7  8  2  3
 2 23  5  7 12  6 11  8 17 22  9 14 10  4  1 21 15 19 13  3 20 18 25 16 24
 3 25 15  1 18  2 14  9 16 20  8 23  7 22 13 12  6 17  5 24  4 21 11 19 10
14  4 11  6 16 10 15  1 23 19 25  3 21 24 18  7 20  2 22  8  5 17  9 13 12
12  5 24 17 15 13  1 16  3  9  6 11 25  8 22  4 23 14  7  2 18 19 10 20 21
 6 16 25 22 23 14 19 15 10  4 21 24 18 12 20  1  3 13 17 11  7  8  5  9  2
10 18 19 21 11 12 17 25  2  7 13  1 23 15  5 20  8 24  9  6  3 14 22  4 16
20  9  7 13  8 22 21 23  6 24  3  4 14  2 16 10 25  5 18 19 15 12 17 11  1
 1  2  3 14  4  5  8 18 20 11 10 19  9  7 17 15 16 12 21 22 24 25 23  6 13
 7 13 22  9 20 11  5 21  4  3 18  2 12 14 10 19 24  8 16 25 23  6  1 15 17
21  3 10  2  1 17 25 24  7 15  5 16 13 23  8 22  4 20  6 12  9 11 18 14 19
18 12 14 15  5 19  6 22  8 23 11 17 20 21  4 13  2  3  1  9 16 24  7 10 25
19 17  6 23 24 16 10 13  1 12  7 15  3 25  9 18  5 21 11 14  2 20  4 22  8
11  8 16  4 25 20 18  2  9 14 19 22 24  1  6 17 10 15 23  7 21  3 13 12  5
16 15 18 19 22 21  4 17 11  5 14 13  8  6 24 25 12 23  3 10  1  2 20  7  9
23 24  4 25 21 18  9 14 22  8 17 12 15 20  7 11 19  1  2 13 10 16  3  5  6
17 11  9  3  6 25 16 20 12  1  2 18 22 10 23  8 21  7 15  5 19 13 14 24  4
 5 10 20  8  2 23  7  3 13  6  1  9 16 19 21 24 22  4 14 17 25 15 12 18 11
13 14  1 12  7 24  2 19 15 10  4 25 11  5  3  6  9 18 20 16  8 23 21 17 22
24  6 12 18 13  1 23  4 19 16 22  7  5  9 14  3 17 25  8 20 11 10  2 21 15
22 19 23 20 14  8  3 12  5  2 24 21  1 18 11 16 13 10  4 15 17  9  6 25  7
25 21  2 16 10  9 20 11 14 17 15  6  4  3 12 23  7 22 24  1 13  5 19  8 18
 4  7  8  5  3 15 24  6 18 25 20 10 17 13 19  2 11  9 12 21 14 22 16  1 23
15  1 17 11  9  7 22 10 21 13 23  8  2 16 25  5 14  6 19 18 12  4 24  3 20

Write the following methods:

The method readSolutions()reads the solution of the puzzle from the file and stores the data in the table and returns this table with numbers. The name of the solution file is specified as the method parameter.
The method checkSudoku()as a parameter receives a table in which the Sudoku solution is written, and verifies that the solution is correct (returns true). In case of an incorrect solution, the method returns false.
4 years ago
I have actually done it with switch instead, but i get an error every time i try to do a multiplication('*').Why is that?
import java.util.Locale;

public class DN03 {
   public static void main(String[] args)throws Exception{
       Locale.setDefault (Locale.ENGLISH);
       int a=Integer.parseInt(args[0]);
       int b=Integer.parseInt(args[2]);
       String operation=args[1];
       switch (operation){
           case "+":
               double zbir=a+b;
               System.out.printf("%d + %d = %.2f",a,b,zbir);
               break;
           case "-":
               double razlika=a-b;
               System.out.printf("%d - %d = %.2f",a,b,razlika);
               break;
           case "*":
               double proizvod=a*b;
               System.out.printf("%d * %d = %.2f",a,b,proizvod);
               break;

       }

   }
}
5 years ago
Hi, the task im currently solving goes like this:
Write the DN03.java program with which you can perform basic computational operations (+, -, #, /, ^)
he results of all operations should be written to 2 decimal places, as shown below:
Example 1: java DN03 5 + 7

5 + 7 = 12.00

Im trying to start with sum but i cant get to even print the sum when i detect it.Any help?
public class DN03 {
   public static void main(String[] args)throws Exception{
       for(int i=0;i<args.length;i++){
           char suma='+';

           if(args[i].equals(suma)){
               int a=Integer.parseInt(args[0]);
               int b=Integer.parseInt(args[2]);
               System.out.println(args[0] + "+" + args[2] + "=" + (a+b));
           }
       }
   }
}
5 years ago
Thanks for all the replies, I solved it with string formatting.
5 years ago

5 years ago

Campbell Ritchie wrote:Welcome to the Ranch

Unfortunately there isn't a straightforward centred option for printing to the console. I am afraid you are gong to have to count characters in your words and calculate the spacing. Let's imagine you have a nine‑letter word to centre in 20 keystrokes' wdth. Use one places for the left *, and that leaves 19. Subtract (9 + 1), the 1 being for the right *. That leaves 9; half of 9 is 4, so try printf:-Alternatively, create a StringBuilder object and append those spaces to it.

You will need to expand my code to get it to work.




But the problem is,i have to make a for loop that will do that for any given word.For example,if I type "Java is cool", the biggest word has 4 characters,the width is the length of that word +4 because i have to give it a space on each side and that a '*' on each side too.So for every next word the spacing can be calculated by (width-current word)/2 but after that i cant align the remaining star.Look at my code at given picture and tell me if I messed something up.
5 years ago
Hi! I am a beginner in Java programming language and i stumbled upon a problem i cannot solve.It goes like this:
Write the DN02 program , which will receive the words received in the arguments, framed and displayed on the screen. Example: when calling a program:
java DN02 That's it!    let the program print:
*******
*    To  *
*    je  *
*    to! *
*******
The text that the program prints in the box must be aligned centrally (shorter words must be aligned in the middle of the space).

As you can see in a given picture, i cant make the right side align the right way.Maybe i should solve it with string formatting but i dont know how.Can someone help me?
Thanks
5 years ago