Posts by Victor Stafusa • 63,338 points
1,321 posts
-
2
votes1
answer54
viewsA: Presentation failing in binary tree
There are a few little problems in your code: #include <conio.h> Don’t use that. This library is super old-fashioned, obsolete and not a standard library. Besides, it’s not being used for…
canswered Victor Stafusa 63,338 -
1
votes2
answers4075
viewsA: Java - method to check whether a String contains a certain character
public static boolean verSeTemAeBeC(String qqString) { return qqString.contains("a") && qqString.contains("b") && qqString.contains("c"); } public static boolean…
javaanswered Victor Stafusa 63,338 -
1
votes1
answer171
viewsA: Error converting value to Jtable
Let’s first simplify your code: private void calcularButtonActionPerformed(java.awt.event.ActionEvent evt) { String posicao = posicaoTextField.getText(); String nome = nomeTextField.getText();…
-
2
votes1
answer70
viewsA: Add one more check, how to proceed?
First, simplify your method by eliminating redundancies. Considering the your previous question, I think it looks something like this: public void verificarResultado() { int linha =…
-
0
votes2
answers154
viewsA: Change variable value within anonymous class
There are two problems here: The method start may take time to actually start the new thread. With this System.out may end up running first. Variables can be in thread-specific caches, and with…
-
2
votes2
answers5377
viewsA: Formatting date in java
Using the new API dava.time, with the DateTimeFormatter: import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.ResolverStyle; class Datas { public static…
-
7
votes1
answer523
viewsA: How to know how many numbers there are from x to y?
function quantosNumerosExistem(x, y) { return Math.abs(y - x) + 1; } document.write( " De 3 até 10: " + quantosNumerosExistem(3,…
-
4
votes1
answer141
viewsA: Is this some kind of "Anonymous Implementation"?
It seems that Runtime creates an "anonymous class" and implements the interface on it. That’s it? Almost. Actually who creates it is the compiler. If you do this within a class Xpto, you may see a…
javaanswered Victor Stafusa 63,338 -
1
votes2
answers737
viewsA: Doubt about displaying inverted array
Explaining the code: // Nome do pacote. package pct; // Essa classe serve para ler dados a partir de uma entrada. import java.util.Scanner; // Todo o código está dentro de uma classe. public class…
-
2
votes1
answer708
viewsA: How to know how many sales for each month?
Internal consultation has a field Year_Month and the external has Year and Month separate. So I will divide the Year_Month in two to stay as the external consultation needs. Doing this separation…
-
14
votes2
answers103
viewsA: What does the expression "/ (?:(?:cats?|dog):)? /" do?
Let’s explain the regex: /.../ - Those / are used in Javascript to denote that what is inside them is a regex. Therefore, the real regex is the ^(?:(?:gatos?|cachorro):)?. ^ - String start. This…
regexanswered Victor Stafusa 63,338 -
1
votes1
answer594
viewsA: Receive user vector in C
That was quite a job to do, but it’s here: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> /*Observacoes: 1, se a ordem nao e decrescente -1,…
-
3
votes1
answer50
viewsA: Where is the error?
Your problem is Javascript errors. Let’s see: function relogio(){ var data = new date(); var horas = data.gethours(); var minutos = data.getminutes(); var segundos = data.getseconds(); if(horas <…
-
8
votes4
answers8801
viewsA: What is it and what is a "truth table" for?
First, let’s start with a simpler question: What is a multiplication table? A table is a table that lists several possible values of an account to be held. For example, in the table of 3, we have 3…
-
1
votes1
answer898
viewsA: Create a Java WEB application that also runs via desktop
Use HTML5 + CSS3. The reason is that if you want to program to the web, the ideal is that the user is running your program through the browser, and so, just know the URL of your program and will…
-
3
votes1
answer155
viewsA: REGEX - problem with validation
What you need to use are regex based on Unicode. Accented characters don’t have an order that makes much sense to mere mortals, and therefore things like á-ú doesn’t work. The class \p{Letter} (or…
-
1
votes2
answers36
viewsA: Creating a custom Writablecomparator class
Try to change that: int keyInt = Integer.valueOf(key1.trim()); int key2Int = Integer.valueOf(key2.trim()); return (keyInt >key2Int) ? 1 : -1; That’s why: return key1.compareTo(key2);…
-
2
votes2
answers804
viewsA: Format Jlabel text with different colors
For the purpose you want to work. All the text of JLabel has to be inside the <html>...</html>. Anything you put out of it will go wrong. For example: import java.awt.Color; import…
-
2
votes2
answers396
viewsA: Doubt about struct and list in c
So you must compile: #include <stdio.h> #include <stdlib.h> typedef struct PESSOA { char nome[100]; int idade; } Pessoa; typedef struct NO { int id; Pessoa pess; struct NO *prox; } No;…
-
2
votes1
answer83
viewsA: Control animation speed using the Jslider component
I got it, it was simple: package trens; import java.awt.Color; import java.awt.EventQueue; import java.awt.Font; import java.awt.Graphics; import java.util.concurrent.Executors; import…
-
4
votes1
answer186
viewsA: Nullpointerexception - Genetic Algorithm
Your mistake is because in main, you create an object of the type Population using the constructor that only receives one int. This constructor creates the array of Individual, but does not fill it…
-
2
votes1
answer64
viewsA: Helps in the logic of conditions and repetition in C++
You can control this with a variable achou that begins as false and when he finds the number sought, changes to true. After the for, if the variable achou for false is because the number was not in…
-
3
votes1
answer187
viewsA: How to move animation in a clockwise direction?
I got it this way: package trens; import java.awt.Color; import java.awt.EventQueue; import java.awt.Graphics; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import…
-
3
votes2
answers1475
viewsA: Find the largest palindrome made from the product of two 3-digit numbers - Python
This one works: i = 0 j = 0 pol = 0 while i <= 999: j = i while j <= 999: temp = str(i * j) tempInverso = temp[::-1] if temp == tempInverso: polTemp = int(temp) if polTemp > pol: pol =…
-
3
votes2
answers267
viewsA: Capture RGBA values
I’m going to base myself on the program I did in this other answer of mine: // Mapeia nomes comuns de cores. Fonte: http://www.w3schools.com/cssref/css_colors.asp var colorMap = {"ALICEBLUE":…
-
4
votes1
answer784
viewsA: How to use Bufferedinputstream correctly?
This is not data corruption. It’s an annoying Java language prank. Most programming languages represent a byte as a number from 0 to 255, i.e., a no sign value (unsigned). For some reason, Java…
javaanswered Victor Stafusa 63,338 -
0
votes2
answers156
viewsA: Calculating between inputs and playing in a variable
First, we use parseInt for try to get a number from a text value. However, if the user type abc in the numerical field, the parseInt will fail and return NaN. That’s where the function comes in…
javascriptanswered Victor Stafusa 63,338 -
2
votes1
answer270
viewsA: Is it possible to group a range of values?
Try this: SELECT t.net, u.hh, t.`data`, t.`local` FROM domingos t JOIN ( SELECT net, updated, HOUR(hora) AS hh, COUNT(*) FROM domingos WHERE `data` = '07/05/2017' GROUP BY updated, net HAVING…
-
3
votes1
answer685
viewsA: Special character error in Java
First, make sure your Jsps include a <meta charset="UTF-8"> inside <head> of the HTML produced and before any other content of <head>. Also, in connection with Postgresql, you use…
-
3
votes2
answers194
viewsA: Different errors in C code on different compilers
Preprocessing The problem is this semicolon: #define MAX 50; The reason is that the #define works (speaking in a somewhat simplistic way) when copying and pasting in the rest of the code the…
-
0
votes2
answers697
viewsA: Regular expression supporting at least two of the four conditions
Try it like this: (?:.*[a-z].*[^a-z])|(?:.*[A-Z].*[^A-Z])|(?:.*[0-9].*[^0-9])|(?:.*[^0-9A-Za-z].*[0-9A-Za-z]) Explanation: (?:.*[a-z].*[^a-z]) - Any string that has a lower-case letter somewhere…
-
1
votes2
answers472
viewsA: How to make one-to-many foreign keys using PHP
You are confusing the concept of column with the concept of table. Watch this table of yours: noticias | categorias | tags ----------------------------------------------- id | id | tag_a…
-
2
votes1
answer279
viewsA: How to draw an image with Canvas?
You can use the method drawImage(Image, int, int, ImageObserver) to draw an image in your Graphics: public void render() { BufferStrategy bs = getBufferStrategy(); if (bs == null) {…
-
3
votes1
answer70
viewsA: Can I create a full app without using swing?
Nothing stops you from using a lot of System.out.println and System.in to make your system. There are also several ways not to use Swing and AWT, such as recreating the equivalent of them using Qt…
-
3
votes1
answer2663
viewsA: How to calculate the logarithm of a number in any java database?
Here is an example: class Logaritmos { public static void main(String[] args) { System.out.println(log(2, 128)); System.out.println(log(5, 625)); System.out.println(log(100, 1000));…
javaanswered Victor Stafusa 63,338 -
5
votes3
answers405
viewsA: How to import all Static variables from another class?
Put that in class A: import static B.*;
-
0
votes1
answer1412
viewsA: (JAVA) Help in Sorting Exercise (Selection Sort and Insertion)
I fixed your program, here’s how it turned out: import java.util.Arrays; class Tres { public static int[] ordenaSelecao(int[] array) { int[] arraySelecao = array.clone(); for (int i = 0; i <…
-
0
votes1
answer103
viewsA: Problem exporting Unity to APK
That doesn’t sound like an error message. It seems to be a message that tells you which command line Unity is running to build your APK.
-
0
votes1
answer133
viewsA: Error: Exception in thread "main" - Stackoverflowerror
Who came first? The egg or the chicken? Look at this: public class Cadastrar { Biblioteca biblioteca= new Biblioteca(); } public class Biblioteca { //Instância das classes das operações Cadastrar…
javaanswered Victor Stafusa 63,338 -
3
votes1
answer47
viewsA: Is there any more beautiful way for me to change the numbers?
How about this? #include <stdio.h> #include <stdlib.h> #include <locale.h> #include <unistd.h> #define tam 20 int main(void) { setlocale(LC_CTYPE, ""); int num[tam]; int…
canswered Victor Stafusa 63,338 -
7
votes2
answers83
viewsA: Set of WHERE , AND and OR conditions in SQL does not produce the expected result
Use like this: SELECT * FROM table_01 WHERE data_reg LIKE '2017%' AND Desc <> 'FRETE' AND Desc <> 'IMPOSTO'; The reason your code went wrong is because you were using the OR. If you were…
-
8
votes3
answers1323
viewsA: Why do pointers have a fixed size independent of the pointed type?
Because a pointer contains a memory address, and all memory addresses are the same size. For example, imagine that the computer’s memory looks like a street with several houses side by side,…
canswered Victor Stafusa 63,338 -
12
votes1
answer155
viewsA: Which programming language uses this syntax?
There are several languages (actually templates tools) that use this notation: Handlebars Angularjs Mustache Dot ... Note that they are all templating tools. They are often optimized to generate…
htmlanswered Victor Stafusa 63,338 -
2
votes2
answers755
viewsA: Generic DAO with CDI error = cannot be cast to java.lang.reflect.Parameterizedtype
Let’s see what that line does: Class<T> clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; First, we get the superclass, including…
-
8
votes1
answer442
viewsA: What is considered a "gambiarra" or a bad code?
Gambiarra is the term used for poor quality and poorly done code, and it doesn’t always work (but sometimes it does, only in a way that shouldn’t be used). Often, it is a confusing code, tied up…
-
0
votes1
answer167
viewsA: How to remove entity classes from Java Persistence mapped in a deleted project?
Close the Netbeans. Access the folder C:\Users\<seu usuário>\AppData\Roaming\NetBeans\8.2\var\filehistory (where 8.2 is the Netbeans version). Delete all subfolders. Reopen the Netbeans IDE.…
-
0
votes1
answer151
viewsA: Help with JPQL query
Just remove the , sum(p.quantidadeRecente) of your JPQL. The sum of the recent quantity of products can then be computed: long quantidadesRecentes =…
-
9
votes5
answers1202
viewsA: How to perform a task at a precise time in time?
In Java: import java.time.ZonedDateTime; import java.time.ZoneOffset; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class Swatch { public…
code-golfanswered Victor Stafusa 63,338 -
4
votes1
answer240
viewsA: Doubt with the Lexical and Syntactic Analyzer Generator (GALS) switch
Note that the variable c is the type char. So if we use characters instead of numbers according to the codes of ascii table, we will have the following: private int nextState(char c, int state) {…
-
0
votes1
answer656
viewsA: Hash function in java
You could interpret the 11 digits as one BigInteger, multiply by a very large prime number (ideally greater than a number of CPF, ie 12 digits), as for example 112287187009. So: private static final…