Posts by Victor Stafusa • 63,338 points
1,321 posts
-
2
votes1
answer14069
viewsA: How can you count repeated numbers in a vector?
The way you put it, there will be a cases where i and j are equal and therefore vetor[i] and vetor[j] are equal, after all comparing a position of the vector with itself will always result in equal…
-
4
votes2
answers458
viewsA: Sort a java List containing null values
First of all, never use public attributes. This is a bad programming practice that should have been abolished and is condemned almost unanimously by experienced programmers. Moreover, it is good…
-
2
votes4
answers9882
viewsA: Program to discover repeated characters in strings and print backwards
If what you want is to count how many letters repeat and how many times, we can use an auxiliary array as an occurrence counter to help. Here’s the code: #include <stdio.h> #include…
-
1
votes1
answer323
viewsA: How to use free in a structure variable (chained list)?
Change this: free(proximo); free(inicio); free(proximo_item); That’s why: while (inicio != NULL) { struct Lista *deletando = inicio; inicio = inicio->proximo; free(deletando); }…
-
1
votes1
answer1566
viewsA: Swap rows from an array
Instead of x + 2 and x - 2 which will only work if you are informed 4 to n, use x + n / 2 and x - n / 2. What is repeated within the two ifs can be moved to before or after them. Remember that the…
-
2
votes2
answers786
viewsA: High demand stock control with Firebird and/or mongodb
Before switching Firebird, I would suggest trying a solution using another transactional database like Mariadb. To give you an idea, Mariadb is used by wikipedia which has a monstrous volume of…
-
4
votes1
answer790
viewsA: Strictly binary tree
Your code is fine, I just have a few suggestions. The first is about this: typedef tipo_nodo *apontador; That, I think, does not contribute much to the readability of the code. I think it is…
-
1
votes1
answer56
viewsA: Error with test cases
There is no reason to look for the height of the biggest pipe. Doing this implies that you did not understand the problem properly. The only thing that matters is the difference between the heights…
canswered Victor Stafusa 63,338 -
2
votes1
answer907
viewsA: Error with Unexpected JPQL token
This is your query, with a few more line breaks: select pes, pEnd from Pessoas pes, PessoasEnderecos pEnd where pes.entidade.idEntidade = :parametroId and where pEnd.entidade.idEntidade=:parametroId…
-
5
votes3
answers430
viewsA: Return method in Java
Just do this: public static void main(String[] args) { String codBarras = "23793.44308.90010.000041.33001.250001.3.52830000008091"; String codBarrasLimpo = codBarras.replace(".", ""); int dv =…
javaanswered Victor Stafusa 63,338 -
6
votes2
answers415
viewsA: Problem with ternary operator
That expression won’t do what you want: k= (i<5)? k++:k; That means the following: Se i < 5, então: Avalia o k (que é zero). Incrementa o k, que será um. Atribui o valor avaliado ao k, ou…
-
5
votes1
answer763
viewsA: Error type Mismatch: cannot Convert from String to String[] - How can I fix?
Your mistake is here: analist.demandas[i] = JOptionPane.showInputDialog("Digite o nome: "); demandas[i] is an array line with several strings. You can’t put a single string there. Your problem is…
-
1
votes1
answer107
viewsA: Simulate Database Update with Select
First, I considered that the structure of the table is this: CREATE TABLE tabela ( re INTEGER NOT NULL, data DATE NOT NULL, is_folga BIT NOT NULL, PRIMARY KEY(re, data) ); In particular, please note…
-
3
votes1
answer53
viewsA: Why does logback use both logback-test.xml and logback.xml as configuration file name?
Drive tests typically include the entire project in the classpath, including configuration files, among them the logback.xml. It turns out that the unit test log settings are usually different from…
-
2
votes1
answer208
viewsA: Connecting led with Arduino using strings
See these links for some inspirations: https://www.arduino.cc/en/Serial/read https://www.arduino.cc/reference/en/language/functions/communication/serial/ Try something like that: #define LED 4 void…
-
3
votes2
answers197
viewsA: Java polymorphism
Think that B is Poodle and A is Cachorro. All Poodle is a Cachorro, but the opposite is not always valid. For example: // Ok. Em uma variável do tipo Poodle, dá para colocar um Poodle sem problemas.…
-
2
votes2
answers93
viewsA: Is there any way to remove all sysout from a Project?
Let’s make a class for this: import java.io.OutputStream; import java.io.PrintStream; public final class Silencio { public static final OutputStream OUTPUT_STREAM_SILENCIO = new OutputStream() {…
-
3
votes1
answer558
viewsA: How to use arrow keys, like up, down, from the keyboard to navigate a list of buttons?
I think it would be something like that (version 2.0): import java.awt.Component; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.KeyAdapter; import…
-
2
votes1
answer212
viewsA: Java @Path and @Produces error
Their importare wrong. What you wanted was this: package resource; import java.util.ArrayList; import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces;…
-
8
votes1
answer159
viewsA: Is this code O(n)?
No! He has a bug that makes him . Let’s see the function maior: int maior(int n, int A[]){ if(n==1) return A[0]; if(maior(n-1, A)<A[n-1]) return A[n-1]; else return maior(n-1,A); } Note that if n…
canswered Victor Stafusa 63,338 -
2
votes1
answer1185
viewsA: Use time. h library for dates
To library time.h contains the following: The guy size_t, which is the resulting type of the operator sizeof and represents a quantity in bytes. This type is also defined in several other libraries.…
-
0
votes1
answer356
viewsA: Scroll between two dates
You can do this by using the API from java 8: long a = ...; long b = ...; Instant ia = Instant.ofEpochMilli(a); Instant ib = Instant.ofEpochMilli(b); LocalDate lda = LocalDateTime.ofInstant(ia,…
-
5
votes2
answers552
viewsA: How best to craft AI for a simple game
If this is a game similar to pong, block-Breaker, Arkanoid or something, artificial intelligence is much simpler than that and genetic algorithms won’t solve it for you. Genetic algorithms serve to…
-
19
votes2
answers1053
viewsA: Problem of the Byzantine Generals. How to implement a solution?
The problem As Comrade Prmottajr said in his answer, the problem of the Byzantine generals is to allow a distributed decision to be made (to attack/retreat or to attack/wait) in the face of the…
-
1
votes1
answer781
viewsA: Size of Binary Tree
Instead: self._Altura(self.raiz) Use this: return self._Altura(self.raiz) That is, the word was broken return. And also here: cont = 0 Use this: cont = 1 Obviously, there are still some cases where…
-
1
votes2
answers167
viewsA: Error with SQL and Mariadb (Current position is before the first Row)
First your code is susceptible to SQL injection and does not close the connection, the res or the statement created. See more about this in that question. By correcting these problems, we come to…
-
1
votes3
answers1909
viewsA: Protecting source code
First, we start with this code to decrypt this mess: function decode(x) { var hex = "0123456789abcdef"; return x.replace(/\\x[0-9a-f][0-9a-f]/g, function(s) { var a = hex.indexOf(s.charAt(2)); var b…
phpanswered Victor Stafusa 63,338 -
2
votes1
answer42
viewsA: Why does this method return me 2?
First, let’s tidy up the identation and visualize the tree formed (adding methods __str__): class No: def __init__(self, dado): self.esq = None self.dir = None self.dado = dado def __str__(self): s…
-
1
votes1
answer190
viewsA: JSP scriptlet code for EL
First, I recommend using UTF-8 instead of ISO-8859-1. The whole world is unifying and universalizing everything around the UTF-8 because it has the advantage of being able to encode any characters…
-
4
votes2
answers91
viewsA: Doubts cast in c
On 64-bit architectures, pointers occupy 8 bytes (i.e., sizeof(int*) == 8). On the other hand, integers have 4 bytes (ie, sizeof(int) == 4). This can be easily proven: #include <stdio.h> int…
canswered Victor Stafusa 63,338 -
6
votes1
answer187
viewsQ: What is the Spectre?
The Spectre is a security breach that compromises a large amount of systems. What is? How it works? What kind of systems and devices are vulnerable? What can be done to defend yourself against him?…
-
8
votes1
answer187
viewsA: What is the Spectre?
What is? The Spectre is a vulnerability arising from a failure of microprocessor designs that allow malicious processes to read memory belonging to other processes. It was discovered along with the…
-
7
votes3
answers390
viewsA: Is it possible to place objects in an Arraylist as soon as instantiated?
If you want a simple changeable list, nothing stops you from doing that: import java.util.Arrays; import java.util.ArrayList; import java.util.List; class MinhasListas { public static <E>…
-
5
votes3
answers390
viewsA: Is it possible to place objects in an Arraylist as soon as instantiated?
From Java 9, you have static methods on the interface List for that reason: List<String> abc = List.of("a", "b", "c"); But the use of this method creates a list that will be immutable, and can…
-
3
votes1
answer820
viewsA: Binary Tree with In-Order and Pre-order Path
In that notation, a sequence of the type (A,(B),(C)) means that A is a knot that has as children the subtrees B and C. Let’s draw this tree: In a binary tree, no node can have more than two…
-
1
votes1
answer94
viewsA: Remove Edittext date and add five years
Using Date, GregorianCalendar and SimpleDateFormat: EditText seuEdit = ...; String texto = seuEdit.getText().toString(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date d =…
-
3
votes1
answer93
viewsA: C Counter Bug - Syntax Problem
count+2; I think you meant it: count += 2; I mean, you forgot about =.
-
0
votes1
answer84
viewsA: Error when starting spring
The problem is that JAXB is no longer in the default classpath of Java 9 and should be added to it. No Maven, that’s it: <dependency> <groupId>javax.xml.bind</groupId>…
-
16
votes4
answers2204
viewsA: How to check if a Localdate is a weekend?
Just use the method getDayOfWeek(). This returns an element of enum DayOfWeek: public static boolean fimDeSemana(LocalDate ld) { DayOfWeek d = ld.getDayOfWeek(); return d == DayOfWeek.SATURDAY || d…
-
4
votes3
answers119
viewsA: Invalidcharactererror
Try this below. Click the blue button Execute down there to test. function unicodeEscape(str) { var map = { '\n': '\\n', '\\': '\\\\', '\f': '\\f', '\t': '\\t', }; return str.replace(/[\s\S]/g,…
javascriptanswered Victor Stafusa 63,338 -
0
votes1
answer496
viewsA: Add element in Jlist
There are two problems here: The first is your variable index be used this way. You do not need this variable, just use the method addElement(E). And you don’t need that if. The second is that you…
-
0
votes2
answers56
viewsA: Difficulties in making select
I think your JOIN itens_pedido itens ON pedido.id_pedido = itens.pedido_id_pedido shouldn’t be there. It is important to keep different names for the different tables consulted to avoid confusion,…
-
2
votes1
answer96
viewsA: What is the error in this activity in c
The average is equal to the sum divided by the total of elements. You are not tracking this total in the variable quant_sal, that’s your problem. In addition, there are several possible…
canswered Victor Stafusa 63,338 -
2
votes1
answer1147
viewsA: Convert String encoded to byte
1-Encrypted text generates the value in bytes: [B@541fe858 Wrong. That’s not the encrypted value. It’s just the result of calling the method toString() in an array. For example: byte[] bytes =…
-
1
votes1
answer1153
viewsA: Element removal at the beginning of C chained list
I’ve revised your code. Below: #include <stdio.h> #include <stdlib.h> struct no { int dado; struct no *prox; }; void imprimir(struct no *prim) { struct no *atual = prim; system("clear");…
-
4
votes2
answers529
viewsA: How to make a minimum ceiling and a maximum ceiling in a random number?
You can do something like this: public class Sorteio { private static final Random RND = new Random(); public static int sortear(int min, int max) { return RND.nextInt(max - min + 1) + min; } public…
-
4
votes1
answer218
viewsA: I made an application/game in java and used MVC. However, I have already concluded and I did not put anything in the Model, is that correct?
The Model is the part of the MVC that specifies what are the rules of its application. I don’t know what kind of game you are playing, but in a typical game, it would be on Model that you would put…
-
7
votes4
answers662
viewsA: How to improve SQL performance with IN clause?
Try this: SELECT c.id, c.nome, c.url FROM categorias c INNER JOIN cliente_categorias d ON d.id_categoria = c.id_ls WHERE c.status = 1 GROUP BY c.url Also try creating an index to make this type of…
-
2
votes1
answer2176
viewsA: Javascript (pure) - Find exact triangle angle according to trigonometric ratio table
You can use the function atan2 for this. Test below: console.log(Math.atan2(233.5, 180) * 180 / Math.PI); The console output is "52.37216305431494". As you may know, the * 180 / Math.PI is to…
-
1
votes2
answers182
viewsA: Nullpointerexception when obtaining latitude and longitude
Let’s see the documentation of the method LocationManager.getLastKnownLocation(String): If the Provider is Currently disabled, null is returned. Translating: If the provider is disabled, null is…