Posts by Victor Stafusa • 63,338 points
1,321 posts
-
1
votes1
answer101
viewsA: Webservice delete error
Error 405 is the Method not allowed. This error indicates that there was a request in a given URL using an HTTP verb that was not suitable. The @DELETE makes it clear that the request should be made…
-
9
votes3
answers1357
viewsA: Is it wrong to use multiple cases for the same action on the switch?
Approach with Map Since your purpose is to set a different color for each region, then: private static final Map<String, String> regioes = new HashMap<>(27); private static final…
-
0
votes3
answers1047
viewsA: Python Indentation Problems in Geany
Looking at the code you’ve posted in an editor that lets you view tabs and spaces so they’re not invisible (Notepad++): All the rest of the file is identado with spaces. I recommend to always…
-
11
votes3
answers2716
viewsA: How to prove the asymptotic order of an algorithm?
The notation Θ The question is always to verify what is the term of the equation that dominates. For this, we use the notation (reads "Téta"). A function belongs to a class if, and only if: That is,…
-
2
votes1
answer82
viewsA: How can I optimize my code?
I will use an approach of creating a JSON table. See the code below. Click the blue button Execute to test. function formatarElemento(e) { return e.length === 2 ? e[0].a + " / " + e[0].b + " - " +…
-
9
votes8
answers4394
viewsA: How to identify "Capicua" numbers that have 5 digits?
It is possible to obtain an estimate of how many digits there are in a number using the logarithm in base 10: The logarithm is a strictly increasing function. So, if we round down its value, we have…
-
1
votes1
answer1386
viewsA: Font Awesome appears as "blocks" in Nginx under Freebsd 10.1
Sometimes I have this problem with uBlock Origin, which ends up blocking the download of fonts from Font Awesome. If this is the cause, the solution is to simply unlock the source in uBlock Origin…
-
1
votes1
answer325
viewsA: Code with indeterminate entries, showing pairs in ascending and odd order in descending order
Your code does not store all read numbers. Therefore, there is no way it can display them later in any order whatsoever. I mean, you’ll probably have to: Use two ArrayLists, one for pairs and one…
-
1
votes2
answers130
viewsA: Show the highest average of all calculated averages
Your main problem is this: if (juiz3<menor) { menor=juiz3; if(juiz3>maior) { maior=juiz3; } } What you wanted is this: if (juiz3 < menor) { menor = juiz3; } if (juiz3 > maior) { maior =…
javaanswered Victor Stafusa 63,338 -
9
votes2
answers1034
viewsA: Why does the absence of the suffix L cause the long variable to be interpreted as int?
The structure of the compiler Internally, the compiler is divided into several parts: Lexical analysis; syntactic analysis, semantic analysis, code generation and code optimization. The first of…
-
5
votes2
answers1829
viewsA: How to find a String inside an Arraylist
The answer from Math has already demonstrated the problem in its method consultaLivro(). But there are still other problems. Basically, in your class Livro, you have these two fields: public final…
-
1
votes2
answers1378
viewsA: Read java strings within a while or do-while repetition structure
Try it like this: package listas; import java.util.Scanner; public class Listas { public static void main(String[] args) { Scanner ler = new Scanner(System.in); while (true) {…
-
4
votes1
answer264
viewsA: Is it possible to compare numerical values in strings without casting to Number type?
This should work from here: public static int seuComparador(String a, String b) { String c = a; String d = b; while (c.length() < d.length()) c = "0" + c; while (c.length() > d.length()) d =…
-
4
votes3
answers536
viewsA: Instanceof with List in JAVA
List<Transaction> is not a List<Object>. List<Data> is also not a List<Object>. The reason is that in a List<Object> you can add any object, while in a…
-
2
votes1
answer79
viewsA: How to get rid of Nan when I erase the i8 field
The trick is to use the function isNaN. In addition, in the function getMoney(el), you multiply by 1000 and then divide by 1000 in calcular(). It seems to me to be a totally unnecessary gambit, and…
-
13
votes4
answers30259
viewsA: Remove accents (javascript)
It would be enough to replace that: var the_title = this.title.toLowerCase(); That’s why: var the_title = retira_acentos(this.title.toLowerCase()); I mean, just call the function retira_acentos…
javascriptanswered Victor Stafusa 63,338 -
1
votes2
answers128
viewsA: Help with summation
You can do it like this: // Inicialmente o conjunto de números está vazio. var numeros = []; // Lê o n. var n = parseInt(prompt("Quantos números você quer digitar?")); // Lê cada um dos n números.…
-
1
votes1
answer523
viewsA: Structure of Repetition in Python
In python, the break does not terminate the loop, but interrupts it immediately. Unlike other languages, you do not have a keyword like fim-while or similar. The compiler/interpreter knows where the…
-
4
votes1
answer312
viewsA: Problem generating random value using Random class
That’s the problem with you if (i == 0) sc.nextLine(); that is in the wrong place. Note that this is after the previous line that has the pessoa[i] = sc.nextLine();. Thus, it does not assign an…
-
3
votes1
answer570
viewsA: Servlet Container (Tomcat) or Application Server?
EJB is a technology for developing distributed applications. The different application servers perform the distribution differently. EJB, CDI, JSP and JSF are just specifications, and the…
-
1
votes1
answer1063
viewsA: Doubt error "Unable to build Hibernate Sessionfactory" Java
This is not compilation problem. That one missing table [tb_cdm] indicates that Wildfly expected to find the table tb_cdm in Postgresql, but this table is not there.…
-
6
votes2
answers858
viewsA: Operator in java
This operator you are looking for is the method contains. His purpose is exactly what you want. If you exchange your array for one Set or List and the solution is simple. For this, you can use the…
-
1
votes1
answer1574
viewsA: Balancing of parentheses
A lot of your compilation mistakes is that now you use Pilha and now uses Pilha *. Always use Pilha *. See its function of creating batteries: Pilha create() { Pilha p; p->topo = -1;…
canswered Victor Stafusa 63,338 -
1
votes1
answer140
viewsA: Is there a command that makes the function resume?
Well, your script would be something roughly equivalent to that: Attempt 1: function fazApostas() { var jaFoi = false; $(".btn-bet.green").click(function() { jaFoi = true; fazApostas(); }); var m =…
javascriptanswered Victor Stafusa 63,338 -
6
votes1
answer403
viewsA: How to use Java 8 Stream in an Object[] list
Use this: List<Integer> lista2 = lista.stream() .map(x -> (Integer) x[0]) .collect(Collectors.toList()); System.out.println(lista2); Exit: [1, 2] See here working on ideone.…
-
2
votes2
answers5228
viewsA: Example login with javascript
I would put valid users in a JSON variable. However, the correct thing would be to validate this in a back-end. Otherwise, it’s very easy to get everyone’s passwords and the security of that is…
-
24
votes1
answer27253
viewsA: Differences @Onetomany, @Manytomany, @Manytoone, @Onetoone
Unidirectional vs bidirectional mapping First of all, it should be noted that each of the relationships @OneToOne, @OneToMany, @ManyToOne and @ManyToMany may be unidirectional or bidirectional. In…
-
7
votes1
answer2391
viewsA: What is Entity Manager?
In JPA, the EntityManager is the class responsible for managing the life cycle of the entities. This class is capable of: Locate entities through the method find (which locates them through its…
-
0
votes2
answers102
viewsA: Create sets for 16-bit variable composed of two 8-bit
#define PORTA (0xAA) #define PORTB (0xFF) #define PORTAB (((PORTA) << 8) | (PORTB)) Or else: #define JUNTAR_16_BITS(a, b) (((a) << 8) | (b)) #define PORTA (0xAA) #define PORTB (0xFF)…
-
1
votes1
answer143
viewsA: Change matrix structure
Let’s create a class first Tabela: import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.format.ResolverStyle; import java.util.ArrayList; import java.util.Arrays;…
-
4
votes1
answer39
viewsA: What is the best way to insert with SQL?
The first way works in Mysql and derivatives, but not in other databases. The second way is the standard way that should work in all databases. Look here at Sqlfiddle.…
sqlanswered Victor Stafusa 63,338 -
2
votes2
answers117
viewsA: "java.lang.Outofmemoryerror" error with List
Based on the Isac response, some improvements can be made: public static List<Integer> fatorar(int x) { List<Integer> numeros = new ArrayList<Integer>(); int aux = x, s = (int)…
-
1
votes1
answer189
viewsA: Check if typed string is in email format
I did it this way: int emailusp(const char *email) { /* Pega o tamanho total do e-mail digitado. */ int tamanho = strlen(email); /* Se for muito curto, cai fora retornando 0. */ if (tamanho < 7)…
-
3
votes2
answers161
viewsA: Position Buttons Scaled Table Using Layouts Manager
I did so, using a BorderLayout to help: import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.EventQueue; import javax.swing.JButton; import javax.swing.JFrame; import…
-
1
votes2
answers82
viewsA: Arrays array loops do not work
Your array bd consists of 3 numbered rows from 0 to 2. Each row has another array with columns numbered from 0 to 2 as well. At the end of the popular part of the array, the value of i will be 3.…
-
0
votes2
answers65
viewsA: What is the behavior of a method that returns integer within the if?
Watch this excerpt: System.out.println("remover(19) = "+remover(19)); if (remover(19) == -1) { System.out.println("O vetor vB está vazio!"); } else if(remover(19) == 1){ System.out.println("Sucesso!…
-
4
votes2
answers1981
viewsA: How to subtract hours in java?
If you can/want to use the java.time, see my another answer. But without using the java.time, can do this by creating a class Horario. That class Horario is a twig-breaker that fits when you don’t…
-
3
votes2
answers1981
viewsA: How to subtract hours in java?
Use the class java.time.LocalTime. See more about her in this other question and answer my. If you want to do it without using the package java.time, see my other answer to this question. Here is an…
-
2
votes1
answer118
viewsA: Problem with linked list of dynamic C implementation
Your code only has two silly little problems. That from here: char palavra = "caio"; fgets(palavra, 3, stdin); That ain’t right 'cause palavra is char, and not char * or char []. I think what you…
canswered Victor Stafusa 63,338 -
5
votes1
answer52
viewsA: Difficulty mounting an SQL statement
I believe there must be a simpler way to do this, but it must work: SELECT u.id, u.nf, u.status, u.date FROM documentos u WHERE u.id IN ( SELECT MAX(d.id) FROM documentos d GROUP BY d.nf ) AND…
-
0
votes2
answers492
viewsA: String counter in Arraylist
Use a Map and the the method compute to assemble a word histogram. Using TreeMap, ordination already comes from grace: import java.util.ArrayList; import java.util.List; import java.util.Map; import…
-
2
votes1
answer35
viewsA: Vector Search - Arrayindexoutofboundsexception
In particular, vet.length is 7 (there are 7 elements). If you pass as parameter 6, it works. The reason for this is because in the way you did, when passing vet.length (7), the method buscaValor…
-
0
votes1
answer97
viewsA: Multiple cast in java
Let’s assume we have this code: public class C {} public class D extends C {} That is, all that is a D, is also a C. But the opposite is not necessarily true. And then this: D d = (D) (C) new D();…
-
2
votes1
answer81
viewsA: How to improve my code?
I think your job processar() it’s no use. I’ll take it. Their variables computador and jogador are actually the number invented by the computer and the player’s attempt. I suggest calling them…
pythonanswered Victor Stafusa 63,338 -
0
votes1
answer745
viewsA: I’m not getting a unit test
Well, first you didn’t post your full code. Missed the imports, the class declaration LoboGuara and the classes Localizacao, Campo, Animal, Ovelha, ObjetoInvalidoException and Randomizador. I put…
-
1
votes1
answer268
viewsA: java Response json out of order
The order of methods in the Class.forName("className").getDeclaredMethods(); is not well defined. See this in javadoc: The Elements in the returned array are not Sorted and are not in any particular…
-
3
votes2
answers585
viewsA: How to cause an Xmlhttprequest error?
According to the page of the MDN*: A XHR request exists in one of the following states: 0 - UNSENT - A client has been created. But the method open() hasn’t been called yet. 1 - OPENED - The method…
-
6
votes1
answer266
viewsA: Inequality in C language
For definition of BMI, healthy would be 18.5 to 25. First, let’s create a function to calculate the BMI: float imc(float peso, float altura) { return peso / (altura * altura); } We could also create…
-
4
votes2
answers1366
viewsA: Discover machine operating system in C
In this answer, I used this: #if defined(__MINGW32__) || defined(_MSC_VER) #define limpar_input() fflush(stdin) #define limpar_tela() system("cls") #else #include <stdio_ext.h> #define…
canswered Victor Stafusa 63,338 -
0
votes2
answers1580
viewsA: Convert utf-8 codes to Unicode
var s = "{\"name\":\"\\u2605 Bayonet\",\"price\":15713,\"have\":6,\"max\":6}"; var s2 = JSON.parse('"' + s.replace(/\"/g, '\\"') + '"'); document.write(s2); I based myself in this answer here at…