Posts by Victor Stafusa • 63,338 points
1,321 posts
-
1
votes1
answer403
viewsA: Table is not generated in Oracle database
Your problem is here: ESTOQUE number (100) not null, A number with 100 digits is beyond what Oracle can process. Its limit is 38 digits. There are two possible exits: Decrease the field size. Change…
-
3
votes2
answers48
viewsA: How to do quicksort animation with canvas
I was able to solve it using the concept of asynchronous functions. To turn your code into asynchronous, I had to rewrite the function sleep. Too many functions just added a few keywords async and…
-
3
votes1
answer559
viewsA: Vector union
The vetC could begin as having all the elements of the vetA and having 20 elements. Then put a for within the other to choose which elements of the vetB you put in the vetC. The for external runs…
-
1
votes3
answers692
viewsA: Financial calculation with decimal large numbers
First, I wonder if the calculation is correct, after all, you are not using the variable parcela in it. In addition pv means present value, and no number of plots, so it makes no sense to iterate…
javaanswered Victor Stafusa 63,338 -
4
votes1
answer2185
viewsA: Convert Roman numbers to Java
You forgot to increment the i within the while internal when the number cannot be subtracted. This causes this while inner be infinite. There were also small problems of using System.out.println…
javaanswered Victor Stafusa 63,338 -
1
votes1
answer996
viewsA: How to call a method that is in another java file?
You have to instantiate the class LRU to use your instance methods (which you do not have static). Also, I see that you will implement various replacement algorithms, so defining an interface will…
javaanswered Victor Stafusa 63,338 -
1
votes2
answers51
viewsA: I can’t check the text boxes
First, your HTML is poorly formed. O <meta charset="utf-8"> should stay inside the <head>. The <center> and the <font face = "Corbel"> should stay inside the <body>.…
javascriptanswered Victor Stafusa 63,338 -
5
votes2
answers275
viewsA: Determine how many "islands" a matrix contains
First, be careful not to read outside the matrix. For example, when i == 0 and j == 0, you do that: if (i == 0) { if (image[i][j + 1] == 0 || image[i][j - 1] == 0 || image[i - 1][j - 1] == 0 ||…
-
4
votes1
answer283
viewsA: When and why to use a parameterized constructor?
The purpose of the constructor is, as the name says, to build the object. Therefore, when the constructor returns, the object that is provided should already be ready for use. An object is properly…
-
2
votes1
answer45
viewsA: I’m trying to test a game but every time I try to run it appears "invalid syntax"
That line: if event.type == pugame.MOUSEMOTION It was meant to be: if event.type == pygame.MOUSEMOTION: That is, you forgot the two-point (:) and wrote pugame instead of pygame.…
pythonanswered Victor Stafusa 63,338 -
2
votes1
answer53
viewsA: How do I create a showOptionDialog method that the default value is "no"?
You can do it: private static boolean perguntar( Component c, String mensagem, String titulo, boolean defaultOpt) { Object[] options = {"Sim", "Não"}; int resposta = JOptionPane.showOptionDialog( c,…
-
7
votes1
answer249
viewsA: I cannot prepare the calculation to solve the problem proposed by the enunciation
First, define this function to simplify your code: long long ler_numero(const char *mensagem) { long long n = -1; do { printf("%s: ", mensagem); scanf("%lld", &n); } while (n < 0); return n;…
canswered Victor Stafusa 63,338 -
4
votes1
answer98
viewsA: Using LISP Functional Programming, respond to exercises?
That defines from here xxx as a function that adds 1 to xxx: (defun xxx (x) (+ 1 x)) That defines from here xxx as having the value 5: (setf xxx 5) LISP keeps values and functions separate. That is,…
lispanswered Victor Stafusa 63,338 -
22
votes5
answers56754
viewsA: What is the difference between syntactic error and semantic error?
[I know this is an old question, but I am not satisfied with any of the answers.] Compilers of most programming languages are divided into several steps: Lexical analysis; Syntactic analysis;…
-
2
votes2
answers387
viewsA: How to calculate two sums with only one button?
You can make a method that is responsible for the calculation, giving you the component ids with the values and then calling this method twice. public void calcular(View v) {…
-
7
votes5
answers357
viewsA: How to dim the blue light on a website?
With a little CSS and Javascript with jQuery I did what follows. Click the blue button Execute down below to test and see the buttons Turn on the light and Turn off the light that arise.…
-
1
votes1
answer36
viewsA: How to use Jekyll’s post system to make app
I built the CSS below. I think you do what you want. I don’t know if it’s exactly the original because you didn’t post the image in its original resolution, but anyway, it’s pretty close. The HTML…
-
4
votes1
answer204
viewsA: How to make the arrow rotate several times until it stops by itself after clicking the button?
This one was challenging and also fun. I combined these things: The SwingWorker with interim results. Concepts of bundle java.util.concurrent. Some concepts I’ve learned working with games such as…
-
7
votes2
answers334
viewsA: Regex validating only normal and leap years in C++
Well, regex is not a good alternative to this problem. Because this is a mathematical problem and regex don’t know how to do math, they just evaluate repetitions in strings. However, as a curiosity…
-
0
votes3
answers577
viewsA: Passing attributes from a Servlet to a JSP
Here’s what you used: value="<%request.getAttribute("id_moto"); %>" Note that you used double quotes both inside and outside, so these quotes do not open and close where you think they would.…
-
3
votes1
answer205
viewsA: Reason for Incompatibleclasschangeerror
A mistake of the kind IncompatibleClassChangeError is usually the effect of an inappropriate compilation process. For example: Create the following classes: public class Teste { public static void…
-
11
votes2
answers1329
viewsA: JAVA: What is the difference between Outputstream and getOutputStream()?
OutputStream is a class. Corresponds to an object that writes sequences of bytes somewhere. There are several other objects that have one method called getOutputStream() which, as the name implies,…
javaanswered Victor Stafusa 63,338 -
4
votes2
answers622
viewsA: How to rotate an arrow inside a circle using Java2d?
You extract the angle from the positions of the arrows and want to rotate the positions. A better approach is to do the opposite: rotate the angle and from the angle extract the position. Follow the…
-
1
votes3
answers473
views -
3
votes1
answer612
viewsA: How to draw an arrow using Java2d?
I made some changes to your code: import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics;…
-
0
votes1
answer774
viewsA: First name, Last name, JAVA POO age
Look at these two methods: public String setNome (String newNome) { this.nome = newNome; } And: public String Sobrenome (String newSobrenome) { this.sobrenome = newSobrenome; } Both declare return…
-
2
votes1
answer137
viewsA: Prisma - How to convert integer to binary?
First, you should avoid global variables and prefer to use local variables. In almost no language use global variable is good programming practice and it is very easy to make up a code tightly tied,…
prismaanswered Victor Stafusa 63,338 -
0
votes4
answers1081
viewsA: Get the contents of the last line of a Java file
For files that are very large (a few gigabytes), most approaches would be to read it sequentially, which would be too slow and could give a OutOfMemoryError if the program stored all this in memory.…
-
1
votes2
answers807
viewsA: How to model n-to-n relationship correctly? Women also have friendship with men and not only men have friendship with women
I would create two relationship tables: amizades_hm and amizades_mh. Both have only two fields: homem_id and mulher_id, both being part of the primary key in both tables: Here is the script to…
-
4
votes4
answers1081
viewsA: Get the contents of the last line of a Java file
Try to use the method Files.readAllLines(Path): import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.util.List; /** * @author Victor Stafusa */ public class…
-
5
votes1
answer944
viewsA: How to pass values by reference in Java?
In Java, whenever you use a parameter of an object type (i.e., it is not primitive), what is passed is a reference to the object (i.e., it is not a copy). With primitive types, the passage occurs by…
-
11
votes1
answer181
viewsA: What is the use of underline in numerical literals?
It only serves to make reading easier. The compiler ignores them. For example, this: private long milisegundosNoDia = 86_400_000; It’s easier to read (by a human) than that: private long…
-
18
votes5
answers19971
viewsA: Validate regular expression name and surname
TL;DR The regex is: ^(?:[\p{Lu}&&[\p{IsLatin}]])(?:(?:')?(?:[\p{Ll}&&[\p{IsLatin}]]))+(?:\-(?:[\p{Lu}&&[\p{IsLatin}]])(?:(?:')?(?:[\p{Ll}&&[\p{IsLatin}]]))+)*(?:…
regexanswered Victor Stafusa 63,338 -
8
votes2
answers13204
viewsA: What is regex to validate only points, numbers and commas?
Would that be: (?:\.|,|[0-9])* Explanation: \. - Dot. , - Comma. [0-9] - Numbers. | - Indicates choice. \.|,|[0-9] - Choose between a semicolon or numbers. (?: ... ) - Grouping without capture. * -…
regexanswered Victor Stafusa 63,338 -
9
votes1
answer2621
viewsA: Why use Class.forName when connecting to the database?
TL;DR It’s not necessary to use Class.forName(String) from Java 6, but doing so can still make your program refuse to boot if the driver is not in the classpath. There is no need, and never has…
-
1
votes1
answer981
viewsA: POST request with Okhttp in JAVA
Your requisition has it from here: multipart/form-data That is, it is a Multipart request, a request that as the name says is made up of multiple parts. These parts are separated from each other by…
-
2
votes2
answers1391
viewsA: Check if the program is running on Windows
Just use the system properties os.name, os.version and os.arch. They are documented here. See a very simple code: class Teste { public static void main(String[] args) {…
javaanswered Victor Stafusa 63,338 -
2
votes1
answer693
viewsA: IP Calculator in JS
Follow the code I made. Only works for Ipv4: function IPv4(input) { // Se o input já for um IPv4, não cria um objeto novo. if (input instanceof IPv4) return input; // Se o "new" tiver sido omitido,…
-
2
votes1
answer27
viewsA: Summarizing the result of several logical tests in a single result
You can do it like this: boolean teste2 = nB < 0.0 && m1 <= j; boolean teste3 = nB < 0.0 && m2 <= j; boolean teste4 = nB > 0.0 && m1 <= 35.0; boolean teste5…
-
1
votes1
answer3293
viewsA: Illegal Attempt to map a non Collection as a @Onetomany, @Manytomany or @Collectionofelements
Your problem is here: @OneToMany @JoinColumn(name = "idGrupoPeca") private GrupoPeca grupoPeca; You should wear this: @ManyToOne @JoinColumn(name = "idGrupoPeca") private GrupoPeca grupoPeca; I…
-
3
votes1
answer1978
viewsA: Java regular expression (validating password)
Does it have to be regular expression? I ask this because determining that using regular expression is necessary seems to me to be a case of XY problem. If the use of regular expressions is not…
-
1
votes3
answers1263
viewsA: How to trigger an event when the value of a variable changes?
Your real problem is that "multiple functions can change the value of that variable at any time". That’s the real problem you have to solve. After solving the problem of the variable being changed…
javascriptanswered Victor Stafusa 63,338 -
2
votes1
answer59
viewsA: Doubt with decision making
Try it like this: private static boolean estaDentro(String resposta, String... alternativas) { return Arrays.asList(alternativas).contains(resposta.toUpperCase(Locale.ROOT)); } public static void…
javaanswered Victor Stafusa 63,338 -
9
votes1
answer677
viewsA: What is the difference between getCanonicalName() and getName()?
TL;DR The difference between the getName() and the getCanonicalName() are those: In arrays classes, the getName() will return [ followed by getName() of the base component. The getCanonicalName()…
-
7
votes3
answers211
viewsA: How to take data from an object and do mathematical operation with another object in C++?
If you have two points a = [x1, y1], and b = [x2, y2], when entering the point c = [x1, y2], you will have a rectangle triangle with the right angle at the vertex c. This triangle has as one of the…
c++answered Victor Stafusa 63,338 -
4
votes3
answers54
viewsA: Date does not receive value more 30 days
You are using the wrong method. See the documentation for method plus(long): Parameters: duration - the Duration, in Millis, to add to this one Translating: Parameters: duration - the duration, in…
-
2
votes2
answers140
viewsA: Instantiate an object throughout the life cycle of the Java application
First, encapsulate the creation of the AmazonS3: private static AmazonS3 criarClient(String usuario, String senha) { BasicAWSCredentials credentials = new BasicAWSCredentials(usuario, senha); return…
-
3
votes2
answers1476
viewsA: Print components of an array in reverse order
Watch this: int i; int vet[i]; cin >> i; /*Tamanho do array*/ That is, you declare the size of the array before reading this size. It should be later. Try to do so: #include <iostream>…
-
1
votes1
answer63
viewsA: Returning different messages according to the results of a function
Try to do something like this: Map<Double, String> mensagens = new HashMap<>(4); mensagens.put(A, "Tipo A"); mensagens.put(B, "Tipo B"); mensagens.put(C, "Tipo C"); mensagens.put(D,…
-
6
votes3
answers701
viewsA: What to do when the argument passed in the constructor is invalid?
Yes, making an exception is recommended. Ideally, a builder should never return a poorly constructed or incorrectly constructed object. If due to the fact that the parameters are not adequate, the…