Posts by Victor Stafusa • 63,338 points
1,321 posts
-
10
votes1
answer12161
viewsA: Hangman game with C functions
I gave him a general review of his code and he went like this: #include <stdio.h> #include <stdlib.h> #include <string.h> char palavra[20]; char forca[20]; char erros[27]; #if…
canswered Victor Stafusa 63,338 -
2
votes2
answers5074
viewsA: What is the use of 'SELECT 1'?
Let’s see this part of SQL: FROM Pagamentos B WHERE A.CPF_Cliente = B.CPF_Cliente AND A.ID_Midia = B.ID_Midia AND A.DataLocacao = B.DataLocacao That’ll bring up some number of records (EXISTS) if…
-
3
votes1
answer35
viewsA: Size of memory addresses
Yes, a memory address that has a size of 32 bits will necessarily occupy 4 bytes in memory.
memoryanswered Victor Stafusa 63,338 -
3
votes1
answer2933
viewsA: How to find the number of rows and columns of a dynamically created matrix?
int** matriz = initMatriz(rows, cols); From that point on, how do I find out the number of rows and the number of columns? Well, the answer is right there. Just look at the parameters rows and cols…
-
4
votes1
answer1505
viewsA: How to run multiple threads sequentially?
It is unusual to find situations where one thread has to expect the other in a serial way. However, these situations exist, and so here goes: Use the method Thread.join(). This is a class instance…
-
1
votes1
answer1154
viewsA: Chained lists in C
First, you’ll have to change the struct carro to say who booked it: struct cliente; struct carro { int codigo; char modelo[30]; struct carro *proximo; struct cliente *reservado; }; struct reserva {…
-
0
votes1
answer101
viewsQ: Resteasy @Form annotation does not work in Glassfish 4.1
I am trying to make a legacy web java application that is packaged within an EAR and that was written for Jboss 7 to work on Glassfish 4.1. The application is not built with Maven nor with Gradle…
-
2
votes1
answer41
viewsA: Access memory allocated on a pointer
How about this? int i, j; for (i = 0; i < tamanho; i++) { for (j = 0; j < 10; j++) { printf("%d ", p[i][j]); } } Note that in the first pair of square brackets, we access an array position,…
-
1
votes1
answer48
viewsA: How to calculate the first 4 bytes of an Address ex: 00F28758
What you want is something like this? using System; public class Test { public static void Main() { int Address = 0x181BA700; int byte1 = Address >> 24; int byte2 = (Address >> 16) &…
-
3
votes2
answers198
viewsA: Create a cross word C++
That will do? #include <iostream> #include <string> using namespace std; int main() { const string c = "ARMANDO"; int t = c.length() - 1; for (int i = 0; i <= t; i++) { for (int j =…
-
2
votes1
answer153
viewsA: Removal item in chained list C
I suppose that Lista be a Elem* and that Lista* be a Elem**. Correct? Let’s see the start of the first function: Elem* no = (Elem*) malloc(sizeof(Elem)); // Aloca um elemento Elem* ant = (Elem*)…
-
8
votes1
answer113325
viewsA: How to fix Forbidden Error 403?
This error means that you have tried to access something for which you cannot have access. An example is trying to access a page that is restricted to site administrators. Another example is when…
-
6
votes1
answer724
viewsA: Where are the instructions for a processor stored?
However, how and where is this instruction information stored? Instructions are stored in the processor itself and are inserted at the time of manufacture? The instructions are stored in memory, and…
-
2
votes1
answer563
viewsA: JDBC Callablestatement: Application hangs when calling Procedure
The first little problem I saw was that there was a } missing somewhere. I put the } that was missing (I assumed that it is before the block catch, at the end of try). Another silly little problem I…
-
1
votes1
answer40
viewsA: isEmpty() method giving error in a while block
Your mistake is here: while ((this.!x[i][j].isEmpty()) && (j<2)) { That one ! after the . is not a valid syntax in java, since after . the name of a field or method should be. Maybe you…
javaanswered Victor Stafusa 63,338 -
13
votes5
answers1899
viewsA: Is dealing with business rules in the model bad practice?
At the risk of giving an opinionated response, I would say that the ideal is to put it on the model, because the model is the layer that represents (or should represent) the state of its…
-
21
votes15
answers4487
viewsA: Determine if all digits are equal
Javascript implementation of the provided formula in Jjoao’s answer. Also includes the tests. function digitosIguais(a) { return a === 0 || Math.floor((a * 9 + 10) / 10) % Math.pow(10,…
-
26
votes15
answers4487
viewsA: Determine if all digits are equal
Let X be the original number. Divide X by 10 and get the rest, call it R1. Repeat while X is non-zero 3.1 Assign R2 the rest of the division of X by 10. 3.2 If R1 is different from R2, return false.…
-
2
votes2
answers586
viewsA: Application does not save data and only saves code
I refactored your code. Whenever possible, use the syntax Try-with-Resources with resources that must be adequately closed such as Connection, PreparedStatement and ResultSet. This syntax ensures…
-
2
votes1
answer138
viewsA: Java, IPVA Expiration Check According to Car Board
The IPVA salary schedule is not decided according to a rigid and well-defined algorithm, but decided according to negotiations and conveniences between the farm secretariats, the DMV and other…
-
6
votes2
answers1818
viewsA: Searching for a matrix within another matrix in Java
Basically, first you identify which is the largest matrix and which is the smallest. With this, you use 4 loops for nestled within each other. The outer loop runs through a from 0 to alturaMaior -…
-
1
votes1
answer42
viewsA: Use generated data in a function
You can use the memory address itself as the identifier. int criar() { int *p = malloc(50 * sizeof(int)); if (p != NULL) return (int) p; else return -1; } However, the way this is, it doesn’t seem…
canswered Victor Stafusa 63,338 -
7
votes2
answers9610
viewsA: Pick current date from machine
Date x = new Date(); The standard constructor of Date creates the object Date with the date and current time of the system clock, as reported by the operating system.…
-
15
votes4
answers31911
viewsA: What is the difference between compiled language for interpreted language?
I was going to write this as a commentary on the other two responses (I started writing this before Maniero posted his reply), but it started getting too big and I realized it would also be an…
-
18
votes3
answers1132
viewsA: When to use finalizers and garbage collection in Java?
The method finalize() is one of the most hated things in Java. The general recommendation is never to use it! In general, try to do resource cleaning on the finalize() is not good practice because:…
-
2
votes3
answers99
viewsA: Method to save multiple "Players" to a list
Try it like this: import java.util.LinkedHashSet; import java.util.Set; public class Party { private final Set<String> players; public Party() { this.players = new LinkedHashSet<>(); }…
javaanswered Victor Stafusa 63,338 -
1
votes3
answers1552
viewsA: How to set index when inserting item in Jcombobox?
Here is a functional example of what you want. Basically the secret is to implement the method toString() adequately. package testes; import java.awt.EventQueue; import java.awt.FlowLayout; import…
-
4
votes2
answers7835
viewsA: What is the difference between c and c++
You are asking two questions here. Basically your questions are: What is the difference between C and C++? Why (between C and C++) to begin studies? About the first question, they are two different…
-
3
votes4
answers5886
viewsA: Language exercise C
First, your example does not compile, because it lacks a }. Look how he gets when properly devised: #include <stdio.h> #include <stdlib.h> int main() { int i, num[6]; printf("Digite 6…
canswered Victor Stafusa 63,338 -
11
votes1
answer6033
viewsA: Using @Supresswarnings in Java
General rules on how to deal with warnings Obviously, the purpose of @SuppressWarnings is to make the compiler not issue warnings. However to use it properly requires common sense. Here are some…
-
5
votes1
answer161
viewsA: Java Nullpointerexception Error
That code is suspicious: public Sensors createSensor(int id, String name, String description, boolean status) { Users user = new Users(); user.sensors[id]= new Sensors(id, name, description,…
-
1
votes1
answer81
viewsA: How to transfer a file with corrupted name?
Sender: Place the file with corrupted name inside a ZIP archive. Rename the file to change its extension to ZUP or ZAP or something else that Gmail doesn’t know what it is. Send the file as an…
-
11
votes6
answers3667
viewsA: Are there objective advantages to a language being "case sensitive" or not?
An advantage of language being case sensitive is that it is easier to enforce code naming rules. Despite this, none of the languages you cited are case sensitive ends up forcing rules of…
-
5
votes1
answer2269
viewsA: What is the difference between setSize and setBounds?
These two codes are practically equivalent: int x = ..., y = ..., w = ..., h = ...; JComponent x = ...; x.setBounds(x, y, w, h); int x = ..., y = ..., w = ..., h = ...; JComponent x = ...;…
-
3
votes2
answers814
viewsA: Checking Time in java
If you are referring to class java.sql.Time, then just use the method valueOf(String): String hora1 = "23:00"; Time n1 = Time.valueOf(hora1 + ":00"); String hora2 = "02:15"; Time n2 =…
-
6
votes1
answer122
viewsA: Error using Random in JAVA
Look at this: int randomico = rand.nextInt(todos.length + 1); combinacao = "" + combinacao + todos[randomico]; According to the javadocs of the method nextInt(int): Returns a pseudorandom, uniformly…
-
4
votes2
answers2008
viewsA: "No value specified for Parameter 1" when executing Preparedstatement
In this method: public class PessoaDao { public void insere(PessoaBean pessoa) throws SQLException{ // conectando Connection con = new ConexaoMysql().getConexao(); // cria um preparedStatement…
-
2
votes1
answer189
viewsA: Purpose of a Webservice
But it wouldn’t be easier for me to connect all these systems in just one database and take all the data from it? Not. The reason is that if you give access to the database, its security, its…
web-serviceanswered Victor Stafusa 63,338 -
3
votes1
answer644
viewsA: Comparison with Stock and Sort
Change this: System.out.print(lista.get(i) + "\n"); That’s why: System.out.print(lista.get(i).getNome() + "\n"); And tidy up your method compareTo(), where you changed the < with the >. Will…
javaanswered Victor Stafusa 63,338 -
7
votes1
answer713
viewsA: CMD, Console, MS-DOS and related terms
Shell means "command interpreter". The Bash is a type of Unix/Linux shell, which contains its own command syntax. The Cmd is the modern Windows command interpreter (CMD.EXE). That is, it is a type…
-
6
votes1
answer324
viewsA: Algorithm Complexity Analysis
First, you can eliminate the h of the algorithm to simplify a little more: int Algoritmo(int A[], int n) { int k=0, i=1, j=0; while (i<n && k+j+1<n ) { if (A[k+j] == A[(i+j)%n]) { j =…
-
0
votes2
answers1040
viewsA: Error connecting to Mysql database in Java
It seems to me that in your class Conexao, you forgot to pass user and password from database to method getConnection class DriverManager. And because of this your Mysql refused the connection as…
-
5
votes1
answer182
viewsA: Jsonexception being launched in Twitter search - Java
Your troublesome JSON consists basically of this: { "has_more_items": false, "items_html": "<um monte de html...>", "focused_refresh_interval": 30000 } That is, basically your code fails when…
-
1
votes1
answer331
viewsA: "Particles" moving with the mouse in the background
Looking at the library code you linked (just click on the "download" button), we find this: /** * Draw particle */ Particle.prototype.draw = function() { // Draw circle ctx.beginPath();…
-
1
votes2
answers557
viewsA: Question about initialized attributes in the constructor in Java
Both will work, but there are important structural differences. When initializing everything in the constructor, it is easier to ensure encapsulation as you are not required to publish setters. In…
-
5
votes1
answer788
viewsA: Monodevelop from Unity says my variables don’t exist?
I’m not Nils, but I’ll answer your question. This is a community where there are thousands of users responding, and Nils is just one of many. Because of this you should direct your question to…
-
1
votes1
answer1494
viewsA: Remove odd numbers from a stack
You have a stack of numbers that we’ll call A. The goal is to get all the odd numbers out of this stack. Since it is a pile, there is no way to go through the elements without necessarily destroying…
-
8
votes2
answers963
viewsA: The if command in java is not working within a method
You didn’t give the methods code AutentificaNome and AutentificaId, but I’ll assume they’re analogous to AutentificaSenha. So I can reconstruct your entire class like this: import java.util.Scanner;…
-
1
votes1
answer1364
viewsA: Add widget in an Array
First of all, this place is wrong: BasicDBObject dbObject = new BasicDBObject(); dbObject = linhas.get(i); The first assigned value will be lost because soon after another value is assigned without…
-
1
votes1
answer639
viewsA: Crawler to log in to the site of nota fiscal paulista
Try it like this: import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import…