Posts by Victor Stafusa • 63,338 points
1,321 posts
-
1
votes3
answers301
viewsA: How to make the if-Else instruction work for reading integers
How about doing it this way? import java.util.Scanner; public class RegistoDeMensagem4 { private static int lerNumero(Scanner kb, String mensagem, String mensagemErro) { while (true) {…
javaanswered Victor Stafusa 63,338 -
7
votes2
answers427
viewsA: Problems with str_pad function and accentuation
The problem is that the function str_pad assumes that each character occupies one byte. When you use characters that are more than one byte long (such as ã), the function starts to go wrong. No…
phpanswered Victor Stafusa 63,338 -
1
votes1
answer191
viewsA: JSONP breaks at two points (" : ")
Since in javascript you expect a JSONP from the server, then the server has to send a JSONP, not a JSON: @GET @Path("email") @Produces("application/javascript") @Consumes(MediaType.APPLICATION_JSON)…
-
1
votes1
answer351
viewsA: SIP connection - Softphone Java Android
The logcat says: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.net.sip.SipManager.setRegistrationListener(java.lang.String,…
-
86
votes4
answers10585
viewsA: What is database normalization?
What is normalization? Database normalization is the process of transformations in the structure of a database that aims to eliminate redundancies and eliminate insertion, update and deletion…
-
3
votes1
answer4641
viewsA: Higher value of a vector, with recursion
First, this function would be called something like this: int valores[] = {5, 10, 4, -4, 2, -7, 9}; int max = maximoR(7, valores); /* 7 = tamanho do vetor. */ Recursively, except when the n is 1, it…
-
2
votes1
answer1630
viewsA: Sequential list implementation exercise
(3) This is the easiest one. Do the following: Create the new method to delete the element, the return is boolean. Scroll through the array using a for. The elements to be covered are from 0 to <…
-
1
votes1
answer122
viewsA: Comparison of JAVA dates
I don’t know if I got it right, but you seem to have an array of Strings containing dates and want to sort this array. If I have understood your question correctly, how about doing so? public static…
-
1
votes2
answers317
viewsA: How to make a Transform. Smoothed translate() in unity5?
Although your question is quite different of your other question (and therefore not duplicated), the answer is essentially the same answer I gave there. There is just one more detail, which is that…
-
3
votes1
answer513
viewsA: How to use Tiles in Unity 5?
I think the solution is for you to maintain a state that says whether it is aligned with the Tiles grid or not. Make the character move until he’s aligned, and don’t let anything stop him until it…
-
1
votes1
answer266
viewsA: Using Inner Join correctly and aggregating results
The first problem I see is that you forgot a detail in your INNER JOIN: INNER JOIN Nota d on ( a.AlunoID = d.AlunoID ) That is, the notes pulled on each tuple are those that relate to the student,…
-
5
votes1
answer1393
viewsA: Save.txt file
Your method busca is recursive and it performs IO operations. Let’s analyze what are the problems with IO: Each recursion of it opens the same file, performs operations on it and closes. Because the…
-
2
votes2
answers495
viewsA: Add interest per plot with Bigdecimal?
Well, I made this class to solve your problem: public final class PrecoComJuros { private final BigDecimal valorBase; private final BigDecimal valorParcelado; // pv private final BigDecimal entrada;…
-
1
votes1
answer58
viewsA: Problem for creating a list linked in C
Let’s see what your code does. First we have this: no *lista, *cabeca; On this line above, you declare the pointers lista and cabeca, not initialized. Then we have this: cabeca = malloc(sizeof(no));…
-
1
votes1
answer3140
viewsA: Group values of different columns into one, comma-separated
What you are trying to do doesn’t seem like a very good idea, and usually when you go down that road, it is a sign that there is something wrong in your understanding of the purpose of the query or…
-
1
votes1
answer1047
viewsA: try to execute the javac command but no longer execute
Your JDK has not been installed correctly. You can download the installer here.…
javaanswered Victor Stafusa 63,338 -
1
votes1
answer45
viewsA: Select accessing two tables
How about this? SELECT p.marker FROM produto p INNER JOIN laptops lap ON p.model = lap.model WHERE lap.model = ? Where ? is the laptop model. However, you might want to show various product and…
-
1
votes1
answer218
viewsA: Calling Java (Android) function inside a hybrid mobile application with Javascript
There is no direct way to do this because javascript will not have an API available in the browser capable of talking directly to the JDK. However, javascript can easily request via Ajax, which uses…
-
9
votes3
answers960
viewsA: How to find a String from Regular Expressions
ATTENTION: Before performing the steps described in this reply, make a backup of your table in case something goes wrong. I don’t think regular expression solves your problem, at least not easily.…
-
2
votes2
answers992
viewsA: Is it possible to pass a method as a parameter to run on a thread?
You can use references to methods that exist in Java 8 on. For example: public class MinhaClasse { public void metodo1() { System.out.println("Metodo 1"); } public void metodo2() {…
-
4
votes1
answer57
viewsA: SQL Database
That would be your SQL: SELECT status FROM Critérios The logic is as follows: A consultation SELECT always produces a table of results. All records in the table are searched Critérios. No filter is…
-
6
votes4
answers635
viewsA: Why can objects other than the same class access private fields from each other?
Because the purpose of access control levels is not that. The idea of encapsulation is to ensure that its classes cannot suffer harmful interference from other classes. That is, if you designed the…
-
3
votes2
answers366
viewsA: What’s wrong with my code? I’m a beginner
I put the description of the most obvious compilation errors in comments: public class Aplicacao { public static void main(String[] args) { Funcionario f= new Funcionario();…
javaanswered Victor Stafusa 63,338 -
1
votes2
answers567
viewsA: Test without "fouling" (adding data) the database
You must use a database for production and another for your tests. Put the name of the database in question to be used in a configuration file, so as to have a configuration file for your production…
-
1
votes1
answer397
viewsA: @Onetomany without Primary Key
What you’re trying to model is the following: A news has N figures. How this works in the database? The table of figures must have a key foreign of the news. What’s in your modeling? The table of…
-
2
votes1
answer155
viewsA: How to modify/evolve a distributed Infinispan cache "hot" without losing entries?
I see at least two possible alternatives, but there must be more. The first of these is the simplest, but also more fragile, and consists of freezing the set of fields of the existing classes (as…
-
3
votes3
answers683
viewsA: Find elements of a class Eno jQuery and add a parameter to them
I think that’s what you want: var contaCliques = 0; $("#btn").click(function() { if (contaCliques == 0) { $(".mudar").addClass("outraCor"); contaCliques++; } else {…
-
3
votes5
answers2439
viewsA: Subtract sums of fields in two separate tables
Basing myself in this other answer of mine, I would do so: SELECT a.c - b.d AS qtdsaco FROM (SELECT SUM(qtdsaco) AS c FROM armazem) a, (SELECT SUM(qtdsaco) AS d FROM armazem2) b…
-
3
votes1
answer252
viewsA: Searching graphs to solve Euler’s theorem
To determine whether the graph is connected, the best approach is probably to search in width or depth. (Reference) To count the degree of each vertex, you can use adjacency list or adjacency…
-
4
votes4
answers8554
viewsA: How do LTRIM() and RTRIM() in Java?
Regex-based solutions are particularly slow and perform poorly for this problem. The reason is that they were designed for significantly more complicated and complex problems than this, and you end…
-
9
votes2
answers5333
viewsA: How to do exponentiation in Java?
Try to use Math.pow: public class ExDesafio_Aula1 { public static void main(String[] args) { double investimento = 5000.00; double juros = 0.01; double valorFinal = investimento * Math.pow(1 +…
javaanswered Victor Stafusa 63,338 -
0
votes2
answers155
viewsA: Easiest way to turn a request into Formdata
You can store headers in a variable: var headersAjax = {'Content-Type': 'application/x-www-form-urlencoded'}; And then, whenever you want to make a request with Ajax with this header, you use the…
-
1
votes1
answer171
viewsA: Can anyone tell me where the bug is please? Is giving "invalid syntax"
Try it like this: n = str(input("Informe o nome do aluno: ")) m = int(input("Informe o numero da matricula do aluno: ")) print("O nome do aluno é: %s, o numero da matricula é: %d" % (n,m))…
-
10
votes1
answer333
viewsA: Why are arrays covariant and generic are invariant?
Covariant arrays are considered a language flaw. Ideally they should be invariant as well. The main reason they were designed as covariants was a poor attempt to allow the implementation of generic…
-
1
votes1
answer881
viewsA: Return of duplicated SQL results
Just put a DISTINCT: SELECT DISTINCT `inte`.`int_nome`, `age`.*, `con_at`.`con_nome` as consultora_que_atendeu, `con_ag`.`con_nome` as consultora_que_agendou FROM (`agendamentos` as age) JOIN…
sqlanswered Victor Stafusa 63,338 -
3
votes1
answer2329
viewsA: Java creation of Register
Your main class: package Sistema2; import java.util.Scanner; import java.util.ArrayList; public class Principal { public static void main (String[] args){ Scanner scan = new Scanner(System.in);…
-
4
votes1
answer97
viewsA: Concurrent list modification can cause "java.lang.Illegalargumentexception"?
Your methods compareTo, equals and hashCode are violating their general contracts yes. Let’s look at them starting with compareTo: Method compareTo @Override public int compareTo(Pai o){ if (this !=…
-
5
votes3
answers149
viewsA: Check two denials in an if expression
Your problem is in interpreting the order in which the subexpressions are evaluated. If you have an expression if (a || b), it will be evaluated so: If a is true, then the whole expression will be…
-
5
votes1
answer374
viewsA: Hibernate, force table name in low box
In your entities, use the annotation @Table. Here’s an example: @Entity @Table(name = "tabela_caixa_baixa") public class MinhaTabela implements Serializable { // ... } When the annotation @Table is…
-
1
votes2
answers217
viewsA: How to capture the status (and readyState) of the IE6 XHR?
Notice that line: var xhr = window.XMLHttpRequest ? new XMLHttpRequest : Notice something wrong? You forgot the parentheses! The right thing would be this: var xhr = window.XMLHttpRequest ? new…
-
5
votes2
answers485
viewsA: Cities and states in XML or Mysql
Three different approaches to locating data The idea of the file until it is good because the registration of cities changes very slowly, then the updates would occur in a very sporadic and casual…
-
4
votes2
answers2375
viewsA: Add real Brazilian currency div
Tell me what you think. The comments in the code explain how it works. // Remove pontos, vírgulas, espaços e marcadores de moeda. function limpar(x) { return x.replace(",", "").replace(".",…
-
3
votes1
answer602
viewsA: Encryption of GET and POST request parameters
You would use some asymmetric key algorithm, and with it you would encrypt the query string GET or the body of the POST request using the public key before sending it to the server (use javascript…
-
1
votes1
answer612
viewsA: How to extract images and sounds and music in the jar file from any Gameloft java games?
The format in which images, music and etc are recorded, is something that is at the discretion of the application developer. Generally, nothing too out of the ordinary would be used, but some…
-
3
votes2
answers1286
viewsA: Multiply the amount of elements from two different tables
I think this is what you want: SELECT a.c * b.d AS produto FROM (SELECT COUNT(*) AS c FROM pessoas) a, (SELECT COUNT(*) AS d FROM carros) b
-
6
votes1
answer469
viewsA: Which HTTP methods use payload?
The default HTTP methods are: Método | Payload no Request | Payload no Response --------+--------------------+--------------------- HEAD | Não | Não GET | Não | Sim POST | Sim | Sim PUT | Sim | Sim…
httpanswered Victor Stafusa 63,338 -
2
votes3
answers88
viewsA: Timer does not run when changing computer date
Looking in class source code java.util.Timer, these code snippets can be located: public void schedule(TimerTask task, long delay, long period) { if (delay < 0) throw new…
javaanswered Victor Stafusa 63,338 -
2
votes3
answers1389
viewsA: How to differentiate device type from IP?
No, what you want is not possible. The IP number is just and only that, a number. And in practice, any device can take any IP number. For example, let’s assume that in my home I have a DHCP with…
-
5
votes2
answers5579
viewsA: How to take only the number after the comma
Why not do that? double teste = 162.0 / 11.0; System.out.printf("%d", ((int) Math.ceil(teste * 10)) % 10); The idea here is: Multiply by 10 so that the first digit after the comma becomes the last…
javaanswered Victor Stafusa 63,338 -
11
votes1
answer250
viewsA: Update system in Java Web
There is much that could be argued against Java, but NONE of these four arguments is true. They are not even distorted or biased versions of reality, they are absolutely and completely false. They…
javaanswered Victor Stafusa 63,338