Posts by Victor Stafusa • 63,338 points
1,321 posts
-
5
votes2
answers218
viewsA: Destructor in C++
Let’s see your main: int main(){ MinhaClasse * mClasseD = new MinhaClasse(1); // A MinhaClasse mClasseE(10); // B return 0; // C } In line A, you create an instance in heap and assign it on a…
c++answered Victor Stafusa 63,338 -
2
votes1
answer79
viewsA: How to make a Javascript animation with Canvas?
I guess you just forgot to put the limpaTela(); at the beginning of the function desenhaCirculo. Click on the blue button Execute downstairs: var tela = document.querySelector('canvas'); var pincel…
-
1
votes2
answers153
viewsA: How to apply decorators that are classes in other class instance methods?
I thank Anderson Carlos Woss. Despite the his answer have indicated me some ways, did not allow me to access things like x.foo.bar, and so it still wasn’t all I needed. Researching further on the…
-
6
votes2
answers153
viewsQ: How to apply decorators that are classes in other class instance methods?
I’m trying to implement a class that’s a method Decorator python. The idea is to apply it to the methods of other classes. However, it is getting lost in the reference self of the annotated class…
-
1
votes1
answer27
viewsA: How to inform columns with contiguous positions?
This method will return one boolean[] indicating which rows have free contiguous positions: private boolean[] buscaContigua(int setor, int contiguas) { boolean[] filasPossiveis = new…
javaanswered Victor Stafusa 63,338 -
4
votes1
answer101
viewsA: MVC and JAVA doubt
First, if you put one JOptionPane on your model, you are already violating MVC. Swing components are things from the view. Do not put anything referencing any user interface in the model. Second,…
-
1
votes2
answers220
viewsA: Why does my Javascript with Class not work?
The method document.getElementsByClassName() back an array. So, you have to access the element in the desired position. Follow your corrected code. Note the indexes [0] used to make it work.…
-
2
votes1
answer56
viewsA: How to avoid the intersection of 2 objects
Create specific methods for this: public static boolean colidiu(double a1, double w1, double a2, double w2) { return (a1 <= a2 && a2 <= a1 + w1) || (a2 <= a1 && a1 <= a2…
-
1
votes3
answers319
viewsA: Build error in C++
There are a lot of errors. This is just the first one that the compiler found. In particular, the use of >> is something C++ uses cout. Already the scanf that is C does not use >>. By…
-
0
votes3
answers20
viewsA: How to delete all files from a directory using Fileutils.cleanDirectory();
Remember that the \ is used for escape sequences. Try using "C:\\PAYGO\\RESP".
javaanswered Victor Stafusa 63,338 -
2
votes2
answers666
viewsA: Simple Java chained list position change
Try to do this: public class No { private int dado; private No proximo; public No(int valor) { dado = valor; proximo = null; } private No posicao(int k) { if (k == 0) return this; if (k < 0 ||…
-
0
votes1
answer51
viewsA: Algorithm for vector ordering
Whatever. When you do not put the value of the step, it is understood that such value is 1. The algorithm you implement is a variant of Selection Sort. However, so you can better glimpse your…
algorithmanswered Victor Stafusa 63,338 -
3
votes1
answer69
viewsA: I am starting in java and am having the error java.lang.Nullpointerexception
at br.com.drogaria.dao.FabricanteDAO.excluir(FabricanteDAO.java:33) That line is as follows: comando.setLong(1, f.getCodigo()); We know that comando is not null and that f is also not null. So the…
-
0
votes1
answer58
viewsA: Removing whitespace from a Numpy Array
Use a function to remove unnecessary spaces. def remove_unneeded_spaces(x): x = str(x) x = re.sub(" +", " ", x) # Remove espaços repetidos. x = re.sub("\[ ", "[", x) # Remove espaços após o [. x =…
-
4
votes1
answer207
viewsA: What are the errors of this chunk of C code that sums the nodes of a binary tree?
In the case of Raiz was NULL, you are returning garbage, since in this case, folhaF is not being initialized. In this case it is best to return zero. I also see that you’re wearing ||, but to check…
canswered Victor Stafusa 63,338 -
3
votes1
answer312
viewsA: Take the value of a dynamic span element
The Ubmit button inside a <form> sends only the data that is inside that <form>. Therefore, only the countryside user_password will be sent. The solution is to use this: <form…
-
4
votes2
answers370
viewsA: Run select from the java DAO class
First, package names should have all lowercase letters and identifier names should follow the pattern camelCase. See more here on the conventions. In addition, class names should be descriptive, and…
-
2
votes1
answer27
viewsA: Do not compile non-static variable and package does not exist
public void automovel(String m, int a){ Now, that was supposed to be a builder, but because of the presence of that void, is actually a method. What you wanted was this: public Automoveis(String m,…
javaanswered Victor Stafusa 63,338 -
0
votes2
answers32
viewsA: Program performance in order of module loading
There is no relevant performance difference in this case. There are some functional differences. For example, if the module to uses the module b and the module b uses the module to, When using…
-
2
votes1
answer31
viewsA: Different web applications use the same connection pool
As far as I know, this is not possible. Each application has its own separate connection pool. I don’t know solutions that seek to share connections pools between different applications. What you…
-
2
votes2
answers81
viewsA: Help with basic C program of the introduction to programming class
Your main problem is that number[i] will contain the value 48 for the 0 and 49 to the 1. The reason is that in the ASCII table, these are the codes for the characters that represent the 0 and the 1.…
-
3
votes1
answer24
viewsA: Very fickle output in multithreaded application along with Exception
The operation System.out.println is quite slow. You make a sequence of 100 instructions System.out.println(lista.get(i)); in the main thread, and therefore outside the thread1 and of thread2. Thread…
-
8
votes2
answers1055
viewsA: If, Elseif and Else with Java 8
The problem is that you are not using Streams, just a lot of Optionals. The way you did, the code is tied to the fact that it has exactly four variables, not just any number. Try it like this:…
-
1
votes1
answer122
viewsA: The Annotation @Persistencecontext is disallowed for this Location
This annotation is not suitable for local variables within the methods. Serves only for instance variables, which are outside the methods and within the class. Do so: @Stateless public class…
-
1
votes1
answer413
viewsA: How to calculate blobs in C?
Before those of yours structare confused. For example, its structure Elem does not seem to represent anything that has any real value. Ideally the image would contain directly the pixels and nothing…
-
6
votes1
answer775
viewsA: Doubt about Chomsky’s hierarchy
The hierarchy The hierarchy of languages is this: The languages Chomsky considered at the time were regular, context-free, context-sensitive and unrestricted. However, I will address all of them,…
-
3
votes1
answer60
viewsA: Dynamic allocation in C
The first problem I see in your code is that x is not being initialized. Therefore, when testing while if the value is different s or S, the result is that the initial behavior is undefined. This is…
canswered Victor Stafusa 63,338 -
5
votes2
answers1656
viewsA: I am unable to perform the following exercise in python
You can simplify your code a little bit and don’t forget to show the excess too, in addition to the fine: pesos = int(input('Digite o número de quilos que você pegou:')) if pesos > 50: excesso =…
pythonanswered Victor Stafusa 63,338 -
8
votes2
answers94
viewsA: Problem when typing str in Python
First, create a function to read numbers that insists until the user enters something valid: def ler_numero(mensagem, tente_novamente = 'Isso daí não é um número. Tente novamente.'): while True:…
-
10
votes2
answers596
viewsA: Why is there such a difference in performance between stream and normal loops?
Well, I took that test: import java.util.stream.LongStream; class Teste { public static void main(String[] args) { var limite = 50_000_000_000L; var x = new long[1]; var inicioStream1 =…
-
6
votes2
answers2077
viewsA: C Encryption - Caesar Cipher
First problem for(i=0; i<tamanhoTexto;i++){ //Lendo o texto a ser encriptado scanf ("%c", &vetTexto[tamanhoTexto]); } Instead of &vetTexto[tamanhoTexto] was meant to be &vetTexto[i].…
canswered Victor Stafusa 63,338 -
11
votes2
answers5035
viewsA: What is the range() function in Python for?
The range is an eternal class. It is somewhat similar to a list, but unlike a list itself, the intermediate values are not stored in memory, and are then calculated as it is iterated based on the…
-
3
votes2
answers1446
viewsA: How to pick up array index?
Your code is riddled with errors: Java is case sensitive. Class name is Integer, and not integer. Cannot instantiate interfaces directly. So, use new List is not allowed. You must instantiate an…
-
4
votes4
answers11232
viewsA: JPA Object References an Unsaved Transient instance - save the Transient instance before Flushing :
Try trading this in your class Endereco: @OneToMany(mappedBy="cliente") private List<Endereco> enderecos = new ArrayList<>(); That’s why: @OneToMany(mappedBy = "cliente", cascade =…
-
6
votes3
answers150
viewsA: Json format is valid, but conceptually incorrect. How to argue?
Syntactically, that’s okay. But the problem here is in semantics. The notation with {} represents an object. The notation [] represents a list. You use this service with the intention of finding a…
jsonanswered Victor Stafusa 63,338 -
0
votes2
answers74
viewsA: Java running 2 programs in parallel
This error is not in the code. It’s something from Intellij. Apparently there is a program already running (maybe an old version that has gone into infinite loop) and you are trying to run it again…
-
1
votes1
answer84
viewsA: Sum of values of a bd column between a time interval - PHP
Try this: SELECT SUM(t.ltsa) FROM tb_abastece t WHERE t.data BETWEEN '2019-01-20' AND '2019-01-30' Obviously, this will only bring up a column as a result, which is the sum. You will only get the…
-
3
votes1
answer3802
viewsA: Error trying to use Javafx 11 with Netbeans 9.0
Java 11 no longer comes with built-in Javafx. Starting with Java 11, Javafx 11 must be downloaded separately here. If you’re using Maven, you can put this in your pom.xml: <dependency>…
-
11
votes1
answer259
viewsA: Sorting algorithm, Java stream
What is the sorting algorithm for this method? I’m in Java 11. First, let’s see how the method sorted() is declared on the interface Stream: Stream<T> sorted(); Ok, that doesn’t help us. It’s…
-
5
votes1
answer681
viewsA: How to get an item from a List< [ ] String>?
I see in your program, you use the following "patterns": Black Cat in a Dark Room. Thunder Mega Zord. An array is worth more than a thousand variables. A little bit of String-Oriented Programming. I…
-
4
votes3
answers971
viewsA: Line with NULL value is disregarded by the SUM function?
To create the database: CREATE TABLE NotaFiscalItem ( nro_nota_fiscal integer, nro_item smallint, qtd_item smallint, vlr_unitario numeric(7, 2), vlr_desconto numeric(7, 2) ); INSERT INTO…
-
5
votes1
answer109
viewsA: About Analysis of Algorithms
I. To define the best (fastest) between two algorithms it is necessary to implement both and perform tests. Whereas this is a question about analyzing algorithms, if you have them just scribbled on…
algorithmanswered Victor Stafusa 63,338 -
1
votes1
answer187
viewsA: I need help with a method
When you do that: public class Macaco extends Animal { private Banana banana = new Banana(); } Are you saying that: Every monkey is an animal. Each monkey has a banana. When you do that: public…
-
2
votes1
answer119
viewsA: Error reading txt file line by line
The problem is that in the file you consider that the nodes are numbered from 1 to 6 while using the indexes numbered from 0 to 5. There are even some places where you use +1 or -1 because of this,…
-
2
votes1
answer889
viewsA: Warning: implicit declaration of Function ːstrlen' [-Wimplicit-Function-declaration]
Use #include <string.h> instead of #include <strings.h>. Notice the difference between plural and singular. However, your program has a lot of other errors: char a[1] = "a"; char e[1] =…
canswered Victor Stafusa 63,338 -
3
votes2
answers102
viewsA: How to display the attributes of an Exception in Python?
I don’t know if I got your question right, but exception classes in python can use the same constructor mechanisms, attributes, properties and methods that any other classes can also. So maybe you…
-
7
votes2
answers469
viewsA: (~ABC)+(A~B~C)+(AB~C)+(ABC)
Let’s start with that: (~ABC)+(A~B~C)+(AB~C)+(ABC) Let’s reorder the expressions: (~ABC)+(ABC)+(A~B~C)+(AB~C) Let’s put the BC and the A~C in evidence: BC(~A+A)+(A~C)(~B+B) Every expression in form…
-
0
votes2
answers212
viewsA: Pointer to struct
The type of vetor is Funcionario* and not Funcionario**. So to get a Funcionario (and not a Funcionario*), you use vetor[blablabla]. As the result of this is a Funcionario (and not a Funcionario*),…
-
1
votes4
answers66
viewsA: Add 0 to the left in an Arraylist <Integer>
Try this: import java.util.stream.Collectors; import java.util.Random; import java.util.SortedSet; import java.util.TreeSet; class Teste { private static final Random RND = new Random(); private…
javaanswered Victor Stafusa 63,338 -
1
votes1
answer71
viewsA: Error Segmentation fault (core dumped) Circular double list
If the list is circular, then you don’t need to scroll to the end of it on insert_front because it means that her "end" is just before the beginning. Therefore, in the insert_front, in the case of…