Posts by Victor Stafusa • 63,338 points
1,321 posts
-
1
votes1
answer1001
viewsA: Error "Setting Property 'source' to 'org.eclipse.jst.jee.server' Did not find a matching Property"
The archive server.xml Tomcat contains an attribute called source. Tomcat doesn’t understand what that attribute is and because of that launches this Warning (warning). This is not an error, it’s…
-
6
votes1
answer3159
viewsA: Replace in the inverted bar " " in java
It occurs that the first parameter of the method replaceAll is a regular expression. Therefore, there are two alternatives: Use the correct regular expression. With "\\\\" in the source code, each…
javaanswered Victor Stafusa 63,338 -
1
votes3
answers1061
viewsA: While Resultset.next() returning only one result
There’s a return within your while. When the return is found, the method ends immediately. Therefore, when reading the first result, the method ends without the other results being processed.…
-
1
votes1
answer103
viewsA: Generate build error in C for not using a function
A typical C compiler has these steps, exactly in that order: Preprocessing. Lexical, syntactic and semantic analysis of the code. Intermediate code generation (object code, these files with…
canswered Victor Stafusa 63,338 -
1
votes1
answer74
viewsA: Problem saving two sales at the same time - JAVA
In its entity Venda, you already have it: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column private Long id; That is, you already tell Hibernate to create the entity id. It will do…
-
1
votes1
answer422
viewsA: How to implement the pessimistic lock in Java WEB EJB?
You can use the method lock(Object, LockModeType) of EntityManager. The way of use is this: AlgumaEntidade x = ...; EntityManager em = ...; em.lock(x, LockModeType.PESSIMISTIC_WRITE); To bring an…
-
2
votes1
answer40
viewsA: How to use Linkedhashset to implement this Ihashset interface?
First, it would be a good idea to make this interface generic: public interface IHashSet<E> { public void put(E data); public boolean contains(E data); public void remove(E data); public…
-
3
votes2
answers141
viewsA: Is it recommended to use memset before strncpy?
That is not the issue to be addressed. In cases where the pointer could be used containing garbage, probably the algorithm/program/function logic is wrong, and put a memset It wouldn’t make her…
-
0
votes1
answer44
viewsA: How to store a word within a vector larger than the word
I do not know code for microcontrollers, but the code you gave does not compile. The error is in the lines you marked: SendDataCmd[] = "blablabla"; This is not how strings are assigned in C. First,…
-
1
votes1
answer228
viewsA: C: Sum between two numbers returns ASCII value or letter
It is not very clear in your code what it is you wanted to do. But a way to convert a character in the track 0-9 to the numerical equivalent is to do this: numero = caractere - '0'; In the case, the…
canswered Victor Stafusa 63,338 -
9
votes2
answers160
viewsA: What are "weak references"? When to use them?
Typical and common references between objects are strong: If object A refers to object B by a strong reference, then object B can only be collected as garbage if object A is also being. With weak…
-
1
votes1
answer851
viewsA: Open Image with My Application
First, let’s start with a viewer code: import java.awt.image.BufferedImage; import java.awt.EventQueue; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import…
javaanswered Victor Stafusa 63,338 -
1
votes1
answer54
viewsA: Unchanging collection adding strings
This static field means that it is impossible to use two instances of MinhaColecaoImutavel. This is a bad idea, after all, there should be no problem in creating two distinct instances of this class…
-
7
votes2
answers95
viewsA: What is the best way to define access to the methods of a class I want to use for unit testing?
First I’ll talk a little bit about inheritance. Inheritance is not for writing tests. Do not use inheritance for this. Indeed, there are people who argue, including myself, that inheritance should…
-
4
votes1
answer1080
viewsA: How to allow only numbers in a javascript prompt?
You can create a version of prompt for this we insist until the user type a number in the form you want: function promptInt(mensagem, tenteNovamente) { var msg = mensagem; while (true) { var ret =…
-
1
votes1
answer418
viewsA: I want the index of a cell, given the column and row numbers
In the case of the first row, first column and first cell may have arbitrary values (not necessarily 0 or 1 and possibly different from each other), the general formula for finding the cell number…
mathematicsanswered Victor Stafusa 63,338 -
1
votes1
answer321
viewsA: "fimenquanto sem enquanto correspondente" error
In your code, you have two se and only one fimse. Was missing the fimse to the first se. Your code should be like this: algoritmo "semnome" var n,i,ma,me:inteiro inicio i<-0 me<-0 ma<-0…
visualganswered Victor Stafusa 63,338 -
1
votes1
answer755
viewsA: Recursively counting sequence of numbers in a C matrix
First thing, from here: if (a) { b; return c; } else if (d) { Can be replaced by this: if (a) { b; return c; } if (d) { I mean, you don’t need else if the if the foregoing ends with a return. The…
-
1
votes1
answer36
viewsA: SQL - Changing Field Names within a Column
You can spin these UPDATEs: UPDATE sua_tabela SET categorias = 'Futebol' WHERE categorias = 'RMS-FUTEBOL'; UPDATE sua_tabela SET categorias = 'Basquet' WHERE categorias = 'RMS-BASQUET'; UPDATE…
sqlanswered Victor Stafusa 63,338 -
3
votes4
answers67
viewsA: Create a role or use the code directly?
The answer is "depends". Knowing which is the best alternative depends a lot on what you want to do. In some cases a function is better, in others, having only the code is better. However, when the…
javascriptanswered Victor Stafusa 63,338 -
2
votes2
answers246
viewsA: TDD with micro services
Best practice depends on the type of test, but it should be borne in mind that the mock is the answer to many problems. You have the microservice To and the microservice B. Like B uses To, you…
tddanswered Victor Stafusa 63,338 -
1
votes1
answer1123
viewsA: Database query error - invalid number
Do JOIN with BETWEEN not a good idea. It’s better to move the BETWEEN to the WHERE. Your CASE also seems to be something more complicated than it should be and can be simplified. I suggest doing…
-
1
votes2
answers65
viewsA: Convert milliseconds to 16-digit hexadecimal
You can use the Math/BigInteger to solve your problem and with it create a hexadecimal converter easily: <?php include('Math/BigInteger.php'); function toHex($n) { $zero = new Math_BigInteger(0);…
phpanswered Victor Stafusa 63,338 -
2
votes1
answer554
viewsA: Data structure - arithmetic expressions
I did it. The result is a monstrous thing. The code below is divided into several parts: Lexical analysis - Divides a numerical expression into a sequence of tokens. A token may be either a number…
javaanswered Victor Stafusa 63,338 -
3
votes1
answer285
viewsA: Take data from a JSON array and add to a list in Java WEB
I saved your JSON in a file meujson2.json. I created this class to represent list items: public final class PagamentoRealizado { private final String tituloNossoNumero; private final boolean…
-
1
votes2
answers332
viewsA: Recursive program doubt for writing vowels in C
First, the int function return escrevevogais is of no use. Therefore, it is convenient to change to void. Second, don’t use gets. I talk more about it in these other answers: 1, 2 and 3. Third, with…
canswered Victor Stafusa 63,338 -
1
votes1
answer793
viewsA: How to check whether the list is empty or with an element in C
Let’s see that code: hash->vet = (lista**)calloc(tamanho, sizeof(lista*)); The hash->vet will point to a memory area that contains an amount of initially null pointers. This amount is given by…
-
1
votes2
answers69
viewsA: Error when user provides file name
The error is here: fgets(nome, 50, arquivo); At this point, arquivo is not a pointer with a valid content. What you wanted is this: fgets(nome, 50, stdin);…
canswered Victor Stafusa 63,338 -
0
votes2
answers205
viewsA: Electron locking when opening more than one application
The Electron is too heavy. The reason for this is that it uses Google Chrome underneath the scenes, and Chrome is a voracious memory, processing, and disk IO eater. See here some references to this:…
-
6
votes2
answers257
viewsA: Mystery Square
Let’s see those ties: //leitura dos elementos for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ scanf("%d", &elem); //somatorio de cada linha aux += i; soma_linhas = aux; } } No matter what…
-
3
votes3
answers6645
viewsA: Union of two vectors in C
Just exchange c[i] = b[j]; for c[j + 5] = b[j];. After all, the first 5 items are for a and the last 5 to b. Without this + 5, you would put the b above those of a. However, how were you accessing…
-
1
votes1
answer1012
viewsA: How to optimize this code (Time Limit Exceeded)?
Use while (!cin.eof()) in place of while(N!= EOF). See here working on ideone.…
c++answered Victor Stafusa 63,338 -
3
votes1
answer193
viewsA: Error reading a long number in java
Arrays should be indexed with int, cannot be with long. Make the variable i was int and this build problem will be solved. The best place to declare the variable i is in the loop itself for. For…
javaanswered Victor Stafusa 63,338 -
3
votes2
answers109
viewsA: How to average N numbers greater than 6
Knowing which is the largest or which is the smallest number does not interest you. Your program does not need this. Within that do-while, you could read a number and if it is greater than 6 (use a…
canswered Victor Stafusa 63,338 -
0
votes1
answer146
viewsA: Java game using Random,Boolean,Scanner,while,if/Else
It would be a lot easier if I could copy the code, change it and put the corrected version in this answer, but you posted the code as a damn image and so it gets hard. The problem is that random…
javaanswered Victor Stafusa 63,338 -
2
votes3
answers113
viewsA: SQL Server - Query logic
First, the COALESCE is your friend. Use it. With it, your query is simplified for this: SELECT *, COALESCE(h, f, d, b, a, 0) AS y1, COALESCE(h, g, f, e, d, c, c, 0) AS y2 FROM valor Note that there…
-
1
votes1
answer50
viewsA: How to make a for in a script tag?
See this field with the ids lat, lng and map within the forEach? So this means that you will generate several elements with these same ids. However, the value of the field id should be unique. The…
-
5
votes1
answer1652
viewsA: Programming C - Swap matrix elements
The problem is here: if (matriz[i][j] == 0){ matriz[i][j] = 1; } if(matriz[i][j] == 1){ matriz[i][j] = 0; } The first if enters when it is zero, and it changes to one. This makes the second if also…
-
1
votes2
answers95
viewsA: List item causing error in C program
Use %d instead of %s to print numerical codes: printf("%d - %s - %s\n", lista[i].cod, lista[i].nome, lista[i].telefone); That is, the first %s was to be a %d. Also, never use the function gets.…
-
0
votes1
answer51
viewsA: Trigger gives error with date
If you do this: SELECT DATE("2018-05-31") + 0; The result will be this: 20180531 If you do that: SELECT DATE("2018-05-31") + 1; Give it: 20180532 That’s the problem. When the i goes to the day 31 of…
-
4
votes1
answer539
viewsA: MVC and DAO standard
Can I include the Student-to-Teacher file to call some method present in this? This would break the pattern? Yes, this does not break the MVC standard. The MVC standard only tells how the model,…
-
3
votes1
answer63
viewsA: Am I doing this exercise right?
There are some errors. The main error is that you should not use == or != to compare Strings. Use the method equals. to avoid having to worry about the case of one of them being null in the method…
-
2
votes2
answers1676
viewsA: java.lang.Noclassdeffounderror running application
You have to run your application like this: java -jar geradorStatus.jar -cp ./lib/jcalendar-1.4.jar
-
0
votes1
answer159
viewsA: Manipulating an object that is present inside an Arraylist
Once you are already using List, then it is better to leave the direct use of arrays there where possible. Since you are already building your objects with all your filled attributes, it is usually…
-
1
votes1
answer645
viewsA: Stone-paper-scissor-lizard-Spock in Uri Online Judge ex. 1873, but he does not accept
Look at this: if(comp == 0) { printf("empate\n"); } if(comp != 0) { Well, if the first if enter, automatically the second does not enter and vice versa. Therefore, it is better to use a else here…
canswered Victor Stafusa 63,338 -
0
votes1
answer46
viewsA: Javascript: Function is not returning the correct value
The call $.ajax(...) is asynchronous. That is, she will not make the call immediately, but will post a request for it to be made. Javascript execution will then find the return result; and return…
-
2
votes1
answer665
viewsA: Convert File string to Float
You don’t seem to know what a character is and what a string is. In particular, this if has no sense: if (strcmp(linha[i],media)) It turns out that linha[i] is a line character. This character will…
-
0
votes1
answer640
viewsA: Error: Conflicting types for 'first'
That one strcat(id,","); will give you trouble. 4 bytes will be allocated to id for the text "N/A" and the null terminator. By doing this you will burst the memory area of the id and start…
canswered Victor Stafusa 63,338 -
2
votes1
answer318
viewsA: How to print tree with indentation proportional to the depth of the node in C?
Your algorithm is much more complicated than it should be. You don’t need to path nor dir. In particular, take a look at this: if(i == depth-2) printf(" "); else if(path[i]) printf(" "); else…
canswered Victor Stafusa 63,338 -
4
votes1
answer183
viewsA: A question with Hashmap
Let’s simplify your code. When you have something like this: if (x) { a; b; c; d1; } else { a; b; c; d2; } Assuming the evaluation of x does not produce side effects in a, b or c or vice versa, you…
javaanswered Victor Stafusa 63,338