Posts by Rafael B. • 507 points
22 posts
-
1
votes1
answer57
viewsA: Video player with RANDOM button
You already have the video array: var lvi = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]; Just mix them with a function of shuffle, as the below: function shuffle(array) { var atual =…
javascriptanswered Rafael B. 507 -
1
votes1
answer151
viewsA: Rotate an image that is in an array
If you are going to work with the one-dimensional array, then there is no such concept of horizontal or vertical. What you can do is replace the position of the colors. But if you want to turn the…
-
1
votes1
answer1229
viewsA: Regular expression for href and www/https/http links
Not use regular expression (Regex) to make HTML parsing. Regex nay is the most appropriate tool to do this. There are several frameworks to do this in almost any language. In PHP you can do it…
-
-1
votes1
answer417
viewsQ: How to extract sentences from a text in Java?
I recently read an article that analyzed the size of the sentences of several authors. It was a stylistic study of his works. How do I read a text (with several paragraphs) and extract your…
-
6
votes1
answer417
viewsA: How to extract sentences from a text in Java?
Starting with the simplest example, we assume that a sentence ends in a dot, followed by a space (or line break): She’s from Rio. He, from São Paulo. All it would take is one split() of the string…
-
1
votes1
answer230
viewsA: Create a Bufferedimage from an int Array
Do not use setRGB, because although it works, it will be less efficient (because it will be setting one pixel at a time). Use the getRaster().getDataBuffer() image to have an access to the pixel…
-
1
votes1
answer481
viewsA: Separate words using split
In this simple example you gave, just split before the ";" and take the first element, like this: public static void main(String[] args) { String str = "Coisa1:kit1:Coisa2:kit2;grupo;grupo2;grupo3";…
-
1
votes2
answers1046
viewsA: Finding numbers in sequence that multiplied is a result
Just one for up to the square root of the number sought: public class Multiplicador { public static void main(String args[]) { try { int i = 16512; int j = encontraPrimeiroNumeroMultiplicador(i);…
-
2
votes1
answer355
viewsA: Hamiltonian cycle taking too long
Determine whether a graph has a Hamiltonian cycle is an NP-complete problem (Source: Wikipedia). Problem NP-Complete means that there is no known polynomial algorithm to find a solution (only to…
-
2
votes2
answers658
viewsA: Ask and store user permission to use full-screen?
Well, you can create a link that points to a window in Fullscreen mode as follows: <a href="javascript:void(0);" onClick="window.open('http://www.google.com', '', 'fullscreen=yes,…
-
2
votes1
answer246
viewsA: How to prove that the algorithm solution is optimal?
Prim’s algorithm serves to find the minimum generating tree of a graph, i.e., a tree with the smallest possible weight of its edges. Source: Wikipedia It starts with any arbitrary node of the graph…
-
1
votes1
answer640
viewsA: How do the <p:editor> of the first faces escape the special characters typed by the user before saving them?
When saving the field to the database, use the Stringescapeutils of Apache Commons Lang: import org.apache.commons.lang3.StringEscapeUtils; // ... String corpoEmailEscapado =…
-
2
votes1
answer376
viewsA: Error String to Int Conversion
This code assumes that the first field of each CSV line is an integer: String[] valores = linhaDoArquivo.split(","); int instante = Integer.parseInt(valores[0]); However it is common to have headers…
-
1
votes1
answer342
viewsA: File upload inside webapp folder
You need to get Servletcontext to call the method getRealPath: String caminho = getServletContext().getRealPath("webapp/uploads/"); File file = new File(caminho); String caminhoCompleto =…
-
1
votes1
answer115
viewsA: I need to get the list of songs
The code is extremely difficult to maintain, and so it has some bugs that you should solve (see below). But to print the list, I suggest creating a toString() method in the Music class: @Override…
-
0
votes1
answer755
viewsA: Return only the first data from a JSON and JAVA array
What you need to do is change the code to get the municipio as a Jsonarray, and if you need to take only the first element, use the getJSONObject method, as the example below: JSONObject js2 =…
-
0
votes1
answer286
viewsQ: Error reading XML with JAXB: all null items after Unmarshal
I have a simple XML stock file with the following format: <?xml version="1.0" encoding="UTF-8"?> <estoque> <item Nome="Impressora XL2N" Peso="13 kg" Armazem="8" Quantidade="12"…
-
0
votes1
answer286
viewsA: Error reading XML with JAXB: all null items after Unmarshal
The error is very simple but difficult to detect. XML is capitalized (Name, Weight, Store, etc). In the Java class, even putting variables with names in upper case is not enough. There are two…
-
2
votes1
answer1278
viewsQ: How to rotate an array (array) in Java?
I have a two-dimensional array, of size M x N, that stores Tiles of a map, in the following format: [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12] And I want to rotate 90º (e.g., turn the map so that…
-
4
votes1
answer1278
viewsA: How to rotate an array (array) in Java?
In the example, the 4x3 matrix can be declared as follows: int[][] a1 = new int[][]{ new int[]{1,2,3}, new int[]{4,5,6}, new int[]{7,8,9}, new int[]{10,11,12}}; That is, it is an array of int…
-
4
votes1
answer684
viewsA: How to transform an array from one dimension to two in Java?
Note that there are several ways to turn a one-dimensional array into a two-dimensional array. See some alternative representations of the example: [1, 2], [1, 2, 3, 4], [1, 2, 3, 4, 5, 6], [3, 4],…
-
1
votes1
answer684
viewsQ: How to transform an array from one dimension to two in Java?
I have an array of one-dimensional integers, like this: int[] a = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; And I want to turn it into a two-dimensional array, for example: [1, 2, 3], [4, 5,…