Posts by Victor Stafusa • 63,338 points
1,321 posts
-
1
votes1
answer102
viewsA: Reading File in java running line specifies if it exists
Use the method split(String) and then remove the name and birth date of the beginning: String linha = /* ... */; String[] partes = linha.split(";"); String nome = partes[0]; String strData =…
javaanswered Victor Stafusa 63,338 -
7
votes1
answer2269
viewsA: Using stack concept to invert words
The errors that prevent the operation of your program are those: In place of frase != '\0' you should have used frase[i] != '\0'. In place of empilha(frase, topo);, you should use empilha(frase[i],…
-
1
votes1
answer305
viewsA: Questions about the Graphics and Graphics2d classes in Java
The method paint(Graphics) in components lightweight (Swing) performs these three things, in that order: Paints the content of the component itself when calling the method paintComponent(Graphics).…
-
4
votes1
answer447
viewsA: Doubt about the price calculation
Let’s start by observing some things from your code: Don’t forget the modifier private. Hardly the package visibility is what you want. It is not good practice to abbreviate or eat letters of…
-
1
votes1
answer26
viewsA: Return a value from a two-variable calculation to show the user using POO. Result is not printed on screen
Use only one Scanner. Use the printf correctly. Or use the println. Your corrected code: Scanner sc = new Scanner(System.in); System.out.println("Insira o valor de Delta S"); double ds =…
javaanswered Victor Stafusa 63,338 -
4
votes1
answer167
viewsA: Parallelizing n queens problem with Openmp
Your parallelization strategy is wrong. The problem is the block delimited with that within the function checkQueen #pragma omp parallel num_threads(n) It turns out that the code of the contents of…
-
2
votes2
answers49
viewsA: Correct display of Radionbuttons
The problem is that the "No" button is hidden behind the "Yes" button": adiciona(jbY, 190, 90, 190, 25); adiciona(jbN, 220, 90, 190, 25); These coordinates mean that the "Yes" is 190 pixels wide,…
-
7
votes4
answers7785
viewsA: Calculate circle area
You don’t need the import java.io.IOException;. Don’t use the close in the Scanner. You should not read the area of Scanner. You must calculate it from the radius. The standard library already…
javaanswered Victor Stafusa 63,338 -
0
votes1
answer66
viewsA: Error to play search screen data for registration screen for editing
The method Cliente.getId() is returning null in his method getAsString(). By calling the toString(), gives a NullPointerException. Change your method getAsString(): @Override public String…
-
0
votes3
answers249
viewsA: Finding an intermediate value between two variables
First, let’s imagine that the board had all 64 squares numbered instead of just the dark 32. For this we need a function that converts its numbering format to a numbering format with 64 squares.…
-
4
votes3
answers249
viewsA: Finding an intermediate value between two variables
You can use the function calculaB down below: This function receives the two numbers a and cand then choose the two values that are in the middle that can be b. These values are obtained by…
-
1
votes2
answers74
viewsA: Variables and if flow control structure in Java
You can do it with three ifs like this: import java.util.Scanner; public class P02IfsTest { public static void main(String[] args){ Scanner keyboard = new Scanner(System.in);…
javaanswered Victor Stafusa 63,338 -
5
votes1
answer617
viewsA: What is a Distributed System
A distributed system is a system that has several nodes running parallel, data processing. Nodes need not necessarily have homogeneous roles in the task performed, and heterogeneity is very common.…
terminologyanswered Victor Stafusa 63,338 -
4
votes1
answer242
viewsA: How to access a pointer within a pointer structure
To make that pointer point somewhere: int teste2 = 123; testado->aponta = &teste2; To change the value of what is pointed: *(testado->aponta) = 456; And to read the variable value:…
-
10
votes2
answers2215
viewsA: Regular expression to find numbers in between words
The regular expression is: (?:Agência: [0-9]{4} Conta: [0-9]{5}-[0-9X])|(?:Conta: [0-9]{5}-[0-9X] Agência: [0-9]{4}) Basing myself in that other answer of mine: import java.util.regex.Matcher;…
-
2
votes1
answer688
viewsA: Swap value of two variables without using a third, using either sum or subtraction only
Can it be using the operator or-exclusive? If yes: #include <stdio.h> int main() { int a = 123; int b = 456; printf("%d %d\n", a, b); a ^= b; b ^= a; a ^= b; printf("%d %d\n", a, b); return 0;…
-
1
votes2
answers3307
viewsA: Concatenating two linked lists into C
Watch this excerpt: if(lis1==NULL){ return lis2; } if(lis2==NULL){ return lis1; } if(lis1!=NULL && lis2!=NULL){ Well, if one of you is NULL, one of these two returnwill have already been…
-
0
votes1
answer38
viewsA: Doubt in SQL Performance
There is no measurable performance difference. Both forms are compiled and optimized for the same internal representation by any modern DBMS, thus having the same performance.
sqlanswered Victor Stafusa 63,338 -
1
votes1
answer241
viewsA: Error running JSF project by eclipse
Caused by: java.util.zip.Zipexception: invalid CEN header (bad Signature) That is, any of the classpath Jars of your application, Tomcat, or even JDK is corrupted. I suggest the following: Try to…
-
1
votes1
answer450
viewsA: Split string with comma as delimiting in Arduino’s Serial.read()
You can use the function Serial.parseInt and then get into it: void gira(char direcao, long valor) { if (caractere == 'R') { giraHorario(valor); } else if (caractere == 'L') {…
-
2
votes2
answers274
viewsA: How to normalize this small database?
Starting with Valdeir Psr’s comment, "category" and "subcategory" tables would be a single table. There would be a field parent_id that would be NULLABLE referencing the parent category. To prevent…
-
4
votes1
answer659
viewsA: Java Recursion - MDC
First, I think you should read the n1 and n2 within the while, otherwise it doesn’t make much sense for you to ask the user that and the while would end up being equivalent to a if. Second, what to…
-
3
votes1
answer42
viewsA: Error in vector calculation in C
Because when you use an array as a parameter in a function, in this case the compiler interprets it as a pointer. That is to say: void bubble(int vetor[]) That’s the equivalent of: void bubble(int…
canswered Victor Stafusa 63,338 -
1
votes1
answer470
viewsA: Problems with Jars
Within the content of MANIFEST.MF of jaxb-impl-2.2.3.jar there’s that: Class-Path: jaxb-api.jar activation.jar jsr173_1.0_api.jar jaxb1-impl. jar If you look at the jaxb-impl-2.2.11 or that of…
-
4
votes2
answers106
viewsA: Performance of ternary operator
Strictly speaking, this depends on the programming language in question, the compiler or interpreter used and perhaps the execution environment. But in practice, the answer is nay, because any…
-
1
votes1
answer30
viewsA: Write numeric topic (1 1.2, 1.2.1) in Mysql with PHP
None of these approaches is the right one. Let’s assume you’re putting the records like this: numero | nome 1 | Teste 1 2 | Teste 2 2.1 | Teste 2.1.1 | Outro teste The solution would be to create…
-
5
votes1
answer253
viewsA: When should a utility class become an injectable dependency?
The class PessoaMapperUtil does not represent a concept of object-oriented programming! Starting from a MVC model, the class Pessoa is your class responsible for shaping the business rules. That is,…
-
2
votes1
answer186
viewsA: Error showing results - URI 1566
I think the problem is here: printf("%d ", vetor[j]); This space at the end will mess up the automatic check of the code output. Try to do so: if (z != 0) printf(" "); printf("%d", vetor[j]); With…
canswered Victor Stafusa 63,338 -
3
votes1
answer667
viewsA: Find all occurrences of a pattern in a String
To class Pattern serves exactly for this, it represents a regex. A auxiliary class Matcher is used to control the search. To search for a regular expression in the middle of a text: import…
-
0
votes2
answers455
viewsA: Read a TXT file and put its content into a Linkedlist
This is more or less a XY problem. Your real problem (X) is how to turn this file into a world and that’s what I answered in the other reply. However, if for some reason you just want the answer to…
-
0
votes2
answers455
viewsA: Read a TXT file and put its content into a Linkedlist
Here’s what I’d do: import java.io.File; import java.io.IOException; import java.nio.charsets.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; public…
-
2
votes1
answer76
viewsA: Help with level system (RPG)
Let’s start with this method: public static int levelToExp(int level) { return (int) Math.floor(1000 * Math.pow(level, 1.5)); } This formula takes the number level, raises to 1.5, multiplies by 1000…
-
11
votes3
answers1710
viewsA: What are the limitations of the object-oriented paradigm?
The object-oriented programming paradigm imposes some difficulties. They may or may not be overcome to a greater or lesser degree. The following list is by no means exhaustive, but should serve to…
-
2
votes1
answer371
viewsA: Encoding problems on the eclipse console
You can specify the correct encoding on builder of the Scanner: final Scanner input = new Scanner(new File("/home/douglas/teste.txt"), "ISO-8859-1"); while (input.hasNextLine()) {…
-
8
votes3
answers651
viewsA: Problem of stopping can be solved in practice?
If at each processor instruction, you dump the 4 Gb of memory (as well as caches, disk and loggers), any programs that are running will eventually repeat a state and you can prove this with the…
computer-theoryanswered Victor Stafusa 63,338 -
63
votes2
answers2825
viewsA: What is a Turing stop problem?
What is a Turing machine for laypeople? A Turing machine is a minimalist mathematical model of a computer with an infinite memory. Although minimalist, all Turing machines are capable of simulating…
-
0
votes1
answer60
viewsA: How do I pass parameter by onclick?
Try wearing something like that: editBtn = '<a type="button" onclick="javascript:Devolver(' + "'XXX'" + ')"><span class="btn btn-danger">Devolver</span></a>'; editBtn =…
-
0
votes2
answers1752
viewsA: How to verify if user has already been registered in the database?
Your code has some problems. First, don’t mix visualization logic JOptionPane with database logic. Considering that your class ConnectionFactory is the of this issue, she has serious problems…
-
1
votes2
answers90
viewsA: How to relate several tables?
I think what you want is this: SELECT m.id_inf_mus AS id, b.nome_banda AS banda, g.nome_grava AS gravadora, q.quant_cd AS cds FROM inf_musicas m INNER JOIN banda b ON m.id_banda = b.id_banda INNER…
-
6
votes1
answer105
viewsA: Is it possible to create the main method in an abstract class?
You can do this, but it doesn’t usually make much sense in practice. A method, even if it is the main, ideally has a connection with the class it is in. This has a direct relationship with the…
javaanswered Victor Stafusa 63,338 -
2
votes1
answer72
viewsA: What’s the mistake in that code?
Floating point numbers are separated with a decimal point, not a decimal point. Moreover, variable names should start with lowercase letters, although the compiler won’t complain about it, it’s just…
javaanswered Victor Stafusa 63,338 -
1
votes3
answers5148
viewsA: Return BD data using List/Arraylist - Java
First, we start with a class that represents a sale. This class is immutable, see the reasons in that other answer of mine: public final class Sale { private final String storeNome; private final…
-
1
votes1
answer512
viewsA: First() and next() methods do not work in Resultset, even when editing parameters
Do not store the Statements and ResultSets in instance variables without having a very strong reason to do so. This way you’re using makes them much more difficult to manage properly and much easier…
-
2
votes1
answer588
viewsA: <c:foreach> does not work
Change items="${listaObjetos}" for items="${listaRegistros}". JSP will search for references to variables in page scopes, request, session, and application (in that order). Your listaObjetos is a…
-
3
votes1
answer73
viewsA: Mount SQL with options
You are listing two records from this table. One of them as the RM and the other with the LC. The standard way to relate records is with the JOIN. Soon: SELECT p.ramal FROM…
-
2
votes1
answer61
viewsA: What’s wrong with these hash algorithms?
Let’s see the code of the builder of DigestInputStream: /** * Creates a digest input stream, using the specified input stream * and message digest. * * @param stream the input stream. * * @param…
-
8
votes3
answers964
viewsA: Use of 'break' in Javascript
You can use a label on for external and use the break with that label: var i, j, text = ""; a: for (i = 1; i <= 3; i++) { for (j = 1; j <= 3; j++) { if (j === 3) { break a; } text += "The…
javascriptanswered Victor Stafusa 63,338 -
5
votes2
answers2071
viewsA: When to use static methods mock?
Static methods are as flexible as granite. If you need to mock a static method, it is a sign that there is something wrong with the design. A static method ideally offers a definite and unchanging…
-
2
votes1
answer76
viewsA: What dependencies do I need on Gradle?
javax.xml.parsers The package javax.xml.parsers matches JAXP and can be found in jaxp-api-1.4.5.jar. For Gradle, you’d use this: compile group: 'javax.xml.parsers', name: 'jaxp-api', version:…
-
2
votes2
answers81
viewsA: Problem when computing average of a grid with empty numbers
To function strtoint can launch an exception if the given string does not have a numeric format. So instead of this: sum :=sum + strtoint(Cells [k, i]); Use this: try sum := sum + strtoint(Cells[k,…