Posts by Victor Stafusa • 63,338 points
1,321 posts
-
0
votes1
answer1926
viewsA: How to create a Primary Key Constraint named in Postgres?
What you want is this command: ALTER TABLE macaco ADD CONSTRAINT id_macaco_pk PRIMARY KEY (id); See here working on Sqlfiddle.…
-
1
votes1
answer452
viewsA: Cells with vectors in C, is showing the elements that have already been removed
Just change the condition of your for in function exibe: for( x=0; x < fim; x++){ printf("%d",pilha[x]); } Note that here I used fim instead of MAX.…
-
2
votes1
answer49
viewsA: Nullpointerexception do not know how to solve
In your class Casa, you didn’t charge the doors. Do this: package introducaoclasses; public class Casa { private Porta porta1 = new Porta(); private Porta porta2 = new Porta(); private Porta porta3…
-
5
votes1
answer246
viewsA: Clear objects with empty subobjects
Just scan the properties of the object and use delete on those that are empty, doing so recursively. See below the function limpar that does this: const obj = { chave1: 'conteudo', chave2: {},…
javascriptanswered Victor Stafusa 63,338 -
8
votes1
answer342
viewsA: Computational Geometry - How to check if two lines intersect only at the anchor?
There are four concepts to consider: Dot Vector Straight Triangle All these concepts are in 2 dimensions. The point and the vector have a coordinate x and a coordinated y. A triangle is represented…
-
14
votes2
answers118
viewsA: Many "if" in an old game for android
Do something like this: // O squareList deve ser uma lista com 9 posições onde os índices estão assim: // +---+---+---+ // | 0 | 1 | 2 | // +---+---+---+ // | 3 | 4 | 5 | // +---+---+---+ // | 6 | 7…
-
1
votes2
answers765
viewsA: Data structure in c++
To use existing libraries instead of creating your own, the ideal is to consult on documentation what are the available. On the other hand, if you want to create your own library, you can create…
c++answered Victor Stafusa 63,338 -
1
votes1
answer43
viewsA: Remove all elements from the list without the Clean() method, is there a way?
Change this: for(int i=0;i<inventário.Count;i++){ inventário.Remove(inventário[i]); } That’s why: while (inventário.Count != 0) { inventário.Remove(inventário[0]); } The reason is that in your…
-
3
votes1
answer865
viewsA: Recursive heapsort in C
First, I created a test for your algorithm: int main(void) { int teste[] = {8, 4, 2, 9, 5, 0, 10, 7, 1, 3, 6}; heapSort(teste, 11); for (int i = 0; i <= 10; i++) { printf("%i ", teste[i]); }…
-
4
votes1
answer372
viewsA: 2597 - Uri Online Judge - C++
Your problem is a number factorization problem. The factorization problem is considered a difficult problem. But considering that N <= 109, then the number cannot have divisors larger than…
c++answered Victor Stafusa 63,338 -
2
votes1
answer55
viewsA: Problem on game startup
The first thing to check is if the files Emoji1.bmp, Emoji2.bmp and midi.mid are present in the same folder as the executable is. To protect against resource problems (images and music) cannot be…
-
3
votes2
answers3588
viewsA: How not to print the line break using the console.log
The instruction console.log has the purpose of debugging and logging. It does not serve to show the output of your program, it is not for that that she was designed. To show some text in the output,…
javascriptanswered Victor Stafusa 63,338 -
3
votes2
answers790
viewsA: Null return for List<String> method
Since you want to return the name of the offices, assuming you are using JPA 2.2, do this: public class Repositorio { @PersistenceContext private EntityManager em; public List<String>…
-
1
votes1
answer233
viewsA: How is Java related to Mysql?
When you go to connect Java with the database (in the case of Mysql), you typically do something like this: Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/basededados",…
-
2
votes1
answer46
viewsA: It is allowed to perform the operation module % with double number in java, and how to change a single position of a string in java?
1: class Teste { public static void main(String[] args) { System.out.println(6.25 % 2.5); } } Output: 1.25. 2: Strings are immutable! That is, you would have to create a new String instead of…
javaanswered Victor Stafusa 63,338 -
2
votes1
answer39
viewsA: Syntax error: Variable problem inside the IF
Use SET fim_preco = blablabla in place of fim_preco := blablabla. See here compiling on sqlfiddle.…
-
3
votes2
answers254
viewsA: Fill Map without duplicating records
Let’s assume your class A have a method getX() that gives the value Long and a method getY() that gives the BigDecimal. With this, you can use the method Collectors.toMap: List<A> suaLista =…
-
0
votes1
answer46
viewsA: Reading of a String
I don’t know if I understood your question correctly, but maybe it was something like this: #include <iostream> #include <string> using namespace std; int main() { string s = "2123dog";…
-
1
votes1
answer217
viewsA: Declare a variable using var or the type itself?
In java, the type is always used in the declaration of a variable. That’s up to Java 9. In Java 10, you can declare with var. And Ambdas parameters have never needed explicit type declaration…
-
0
votes1
answer587
viewsA: Exception in thread "main" java.lang.Noclassdeffounderror: org/apache/logging/lo g4j/Logmanager
C:\Unky\Web\BloodStrikeServer-master>mvn clean package -Dmaven.test.skip=true 'mvn' não é reconhecido como um comando interno ou externo, um programa operável ou um arquivo em lotes. Maven is not…
-
2
votes1
answer570
viewsA: How to format a number in percentage within Javascript?
Rounding forms First you have to keep in mind that there are several possible ways to round up a number. I see that in your code, you use SQL, Javascript and also Java since you are using JSTL, so I…
-
1
votes1
answer46
viewsA: Using a NOT Criteria with Hibernate
Try to use this: crit.add(Restrictions.ne("conta.nrOrdeTitl", 2L)); The name of the method ne means not equals, that is, it is the opposite of eq which means equals. Ah, and don’t use things like…
-
0
votes1
answer13
viewsA: Case with parameter in Interbase 2017
Apparently your idea is to apply the WHERE only when the :ID_CATEGORIA is different from zero. And when the :ID_CATEGORIA for zero, you want all results to be brought. Try using a OR: WHERE…
sqlanswered Victor Stafusa 63,338 -
0
votes1
answer130
viewsA: Add values from an array with different criteria each of them
Using strings where numbers should come in your JSON is not a very good idea. It’s best that the JSON numeric fields come with even numbers. I made a code that should solve your problem.…
-
3
votes1
answer1777
viewsA: How to delete a specific object in HTML5 canvas?
How can I delete only one specific? And how can I associate events to one specific event? You can’t. At least not easily. Think of the canvas as if it were the canvas in a program like Paint where…
-
25
votes3
answers1712
viewsA: Why is it considered wrong/bad to repeat an HTML ID?
Because the purpose of id is to be a unique identifier for the HTML element where it is applied. If he is not unique, this goes against the idea for which he was conceived, and it makes no sense to…
-
1
votes2
answers69
viewsA: Search is not performed after connecting to the Java database
Well, your job is to conectarBanco() open the connection, show "Conectado!" and then close the connection. Only after the connection has been closed do you try to extract some information from the…
-
1
votes1
answer93
viewsA: Hibernate no Excludes
Try adding a em.flush(); after the em.remove(p);. As for these warnings, they are the result of the concept of modularization introduced in Java 9. Many tool developers using Reflection were very…
-
5
votes2
answers1995
viewsA: What does "== $0" represent when inspecting a page?
It is the element that is selected. It can be referenced in the Javascript console with the variable $0. For example (using jQuery), if you type this in the console: $($0).html() The HTML of the…
-
1
votes1
answer352
viewsA: Limit an Edittext from 1 to 100 and include the "%" symbol
Analyzing the Maskformatter code on Github, I think the easiest approach is to implement the TextWatcher directly. The MaskFormatter doesn’t seem to have been made for a case like the one you have.…
-
2
votes1
answer338
viewsA: No serializer found for class sun.security.util.Objectidentifier
First, let’s invent a functional implementation for your method generateRSA: public class SecurityOperations { public static KeyPair generateRSAKeys(int keySize) { try { KeyPairGenerator…
-
4
votes1
answer371
viewsA: Second backslash in metacharacters when the expression is in quotes
Within strings, the \ is used to encode escape sequences. That is, it is used to encode things that would be difficult to place inside the string in some other way. For this we have the \n denoting…
-
0
votes1
answer89
viewsA: progamma error
You forgot to convert user input from string to integer: resultado = trianguloPascal(int(n)) See here working on ideone.…
-
1
votes3
answers44
viewsA: Send form without knowing the name
Instead of generating one name random to the form, generate a id random: function altera(ide) { var form = document.getElementById(ide); alert(form.teste.value); // Para você se certificar que pegou…
-
4
votes3
answers354
viewsA: Close() method in Try and catch blocks is necessary?
The safest way to use the close() is indirectly, with the Try-with-Resources. The Try-with-Resources was introduced in Java 7 which was released in 2011. So if you’re seeing older articles, they…
-
2
votes1
answer120
viewsA: Calling a static method by name as string in Javascript
I’m not sure I understand what you want, but maybe this is it: class Transformation { static operate(function_name, object) { Transformation[function_name](object); } static move(object) { alert("oi…
-
10
votes1
answer372
viewsA: Execution Time in Programming Solution Challenge
Your problem The problem is this: Imagine a 100,000-story building that firefighters insist on thousands of times to know how many people there are up to the top floor. This will make your program…
canswered Victor Stafusa 63,338 -
6
votes1
answer252
viewsA: In a map/reduce in Java, should the accumulation operation generate a new object? Or can I use the old one?
Well, you didn’t say what you use as class T nor what are those functions that operate on it to produce Strings. Then I will invent a class for this: class Colorido { private void complica() { try {…
-
1
votes1
answer33
viewsA: jQuery function for selecting values in Divs and playing for an array
Try this: var array = []; $('.card-header').each(function(i) { array.push($(this).html()); }); $('.rodapeCat').html(JSON.stringify(array)); <script…
-
4
votes1
answer226
viewsA: Netbeans Java Error: "error: Diamond Operator is not supported in -source 1.5"
First, right-click on your project to see the drop-down menu of the figure below, where you see the item "Properties" or "Properties": When opening the properties, change the source code box to JDK…
-
1
votes1
answer55
viewsA: How to delete a file (not txt) in C?
You cannot delete a file that is open. Close the file with fclose(consultar); before trying to delete it. And please don’t use gets never. Reasons not to use gets I’ll explain in this answer and…
-
2
votes4
answers1245
viewsA: Hibernate - How to search all rows of a table with Hibernate?
You can do it: public <T> List<T> listarTodos(Class<T> tipo) { return em.createQuery("FROM " + tipo.getSimpleName(), tipo).getResultList(); } You’d wear it like this:…
-
2
votes1
answer45
viewsA: Problem with BD (foreign key)
There are some silly little problems in your script. The cause of your problem is that the table markers is as MyISAM. MyISAM has no foreign key support, and do not recommend using MyISAM for…
-
2
votes1
answer64
viewsA: How to get a specific field of a class even though it is inherited
Try something like that: public static Field acharField(Class<?> onde, String nome) throws NoSuchFieldException { if (onde == null) throw new NullPointerException(); if (nome == null) throw…
-
3
votes2
answers309
viewsA: Error while updating Java
This is not the answer I’d like to post, but come on: First, I found more people reporting this bug or at least something very similar: https://stackoverflow.com/q/47216694/540552…
-
3
votes2
answers309
viewsA: Error while updating Java
Somewhere in your project CadastroDeProdutos there must be this: import sun.misc.BASE64Encoder; For example, let’s compile this class below: import sun.misc.BASE64Encoder; public class Teste {} By…
-
1
votes1
answer526
viewsA: How to implement a Recursive Merge
First, I set up a test for your code: void mergeSort(int v[], int tamanho) { mergeSortInt(v, 0, tamanho); } int main() { int a[] = {10, 2, 7, 1, 4, 9, 3, 8, 0, 5, 6}; mergeSort(a, 11); for (int i =…
canswered Victor Stafusa 63,338 -
6
votes4
answers1092
viewsA: Doubt with switch in Javascript
Note that in your case, if anos has exactly the value 7, would not fall in any of the cases and nor in the default. I think the condition of default should be >= 7 instead of > 7. The block…
-
0
votes1
answer33
viewsA: Add the value 5 at the end of the list/tuple
I think what you want is this: lista_da_tupla_a = (["0", "33", "40"], ["8", "30","9"], ["7", "0", "0"]) for tuplinha in lista_da_tupla_a: tuplinha[2] = "5" print(lista_da_tupla_a) I mean, you use…
-
1
votes1
answer79
viewsA: Help in joining these two Mysql queries
First, I think the and qs.slot=qa.slot should be moved into the JOIN correspondent. I’m gonna kick that speaker itemtype, itemmodule, finalgrade and aggregationstatus are on the tables gg and gi. If…
mysqlanswered Victor Stafusa 63,338