Posts by Math • 30,313 points
252 posts
-
2
votes4
answers1240
viewsA: I want to take only the first digit after the point of a number that in python 3.7.4
At the suggestion of anonymity, multiply by 10 and take the rest of the division by 10 ignoring the decimals. By multiplying 3.76443 by 10 the number turns 37.6443, the rest of the division by 10 is…
-
9
votes2
answers2728
viewsA: How to separate only the first word of each string from a list?
Code: nomes = [" Paulo Ricardo ", " Fabio Junior ", " Roberto Carlos "] n = [nome.strip().split(' ')[0] for nome in nomes] print(n) Upshot: ['Paulo', 'Fabio', 'Roberto'] Explanation: strip() to take…
-
1
votes1
answer2090
viewsA: Edit data from a Dropdown List in Excel
Go to the data menu (1), data validation subset (2), as you already have a list in the validation criterion the option allow should be as list (3), edit the source or the contents of the cells…
-
8
votes3
answers883
viewsA: How to create operators in Python?
In Python you cannot create operators, but you can overwrite them, for that you need to reimplementate the magical methods also known as dunders (abbreviation of double underlines). See the list of…
-
5
votes2
answers68
viewsA: IF always gives me the same answer!
You created a variable with the name "drink" when actually you should use a literal string, if you want to compare a variable with a string this variable should also be of the type string, so change…
-
1
votes1
answer379
viewsA: Problem to run file. Feature in Pycharm
This error occurs only when trying to rotate the .feature passing the name of a specific scenario with the --name or -n. That’s why the re.LOCALE was deprecated from version 3.6 but not removed from…
-
4
votes2
answers1829
viewsA: How to find a String inside an Arraylist
In your query you scan the list but stop the loop in the first element being the title of the book found or not when using the breaks within the if and of else for (int i = 0; i < livros.size();…
-
2
votes1
answer42
viewsA: Seek word with accuracy
Code: import re text = "be besides being bee be, be. before, Be Be. forbe be_ be3 be" be = re.findall('(\\bbe\\b)', text, re.IGNORECASE) print(len(be)) print(be) Upshot: 6 ['be', be', be', be', be',…
python-3.xanswered Math 30,313 -
0
votes1
answer85
viewsA: print numbers using Tostring in java
You created a method but you didn’t call it. Create a main method and call it inside it. Example: public static void main (String[] args) { ToString2(); } See it working on Ideone:…
-
1
votes3
answers966
viewsA: How to store an int and a complete string from within an input?
You can use the Partition to separate the string by the first occurrence of the character you pass as parameter, in case you want to separate by the space character of the string. Example: entrada =…
-
1
votes1
answer94
viewsA: Error accessing Jtable line
Looking through your image would say that you are trying to get the index of the selected line when there is no selected line, see in documentation: public int getSelectedRow() Returns the index of…
-
3
votes1
answer247
viewsA: Autocompletetextview with accented words
Before making the comparison you can remove the String accents from your Autocompletetextview in the method performFiltering(), using for example Normalizer: System.out.println(Normalizer…
-
8
votes3
answers184
viewsA: Search in String
An example of how to separate snippets starting with # and even find a blank: import java.util.regex.*; class Ideone { public static void main (String[] args) throws java.lang.Exception { String…
-
0
votes1
answer60
viewsA: Code the closure of an application
In its main class, namely the one that extends from Application and has the method start(Stage stage) implemented, override the method stop() and implement what you wish in it: @Override public void…
-
8
votes2
answers7914
viewsA: What is the difference between Java Keywords extends and Java Implements?
implements is used when a class implements an interface, extends is when a class extends another class (concrete or abstract) or when an interface extends another interface. That is, the keyword…
-
5
votes2
answers257
viewsA: string formatting
Mount a substring with the initial index at the opening of the parentheses and that goes all the way to the end. str = 'CARLOS MANGUEIRA (0-2) 1' # string de exemplo index = str.find('(') # indice…
-
4
votes2
answers1793
viewsA: Only get the first name, after space using Java
Just you use the pattern \\S+ Example: import java.util.*; import java.util.regex.*; import java.lang.*; import java.io.*; class Ideone { public static void main (String[] args) throws…
-
5
votes5
answers7965
viewsA: Some way to get the price of the dollar
Fixer.io To Fixer.io which is a free and simple to use API. Giving a GET at the address http://api.fixer.io/latest?base=USD&symbols=BRL you have a JSON as a result:…
-
1
votes1
answer533
viewsA: Linkedlist in Java
In doing LinkedEventos = Compra; you are making the variable LinkedEventos reference the same as the variable Compra. From that moment any modification you make to the object referenced by the…
-
3
votes3
answers1358
viewsA: How to create a variable through the answer typed by the user in Python?
The variable is just a name to reference an object that occupies a memory position. At runtime the variable name is completely irrelevant since no one will be viewing it at this point. The variable…
-
5
votes1
answer132
viewsA: Trayicon with hidden console
From what I’ve seen you’re no longer having problems with Trayicon, you just want a windows console window not to wait for the end of running your program. To solve this obstacle you can use the…
-
11
votes3
answers7080
viewsA: In a list, what is the difference between append and extend?
In the append() you add elements to the end of the list, in extend() a iterable as argument, and this argument is added to the end of the element-by-element list. If you have a list and want to…
-
6
votes3
answers756
viewsA: Get larger number of items in a Python list array
You can iterate your matrix by creating a Generator and using a len() to pick up the size of each element, thus: gen = (len(x) for x in matriz) and then use the function max() to catch the biggest…
-
6
votes4
answers392
viewsA: Read Internal File Name
Can do with listFiles or Files walk. java 8. import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Stream; class Teste { public…
-
5
votes2
answers2001
viewsA: Python Basic Request
You can use the lib requests. Import via the Pip: $ pip install requests Example: >>> import requests >>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))…
-
2
votes4
answers4551
viewsA: Recursive multiplication in C
Some points to be improved: Checking on the first if is unnecessary, you need to treat the n which is the number of times your code is iterated, never the v, which must be a fixed value to be added…
-
6
votes2
answers145
viewsA: Error compiling code with import java.util.Random; Random.nextInt()
The real problem you should note in the first line of error: Random is already defined in this Compilation Unit You gave Random’s name to your class, and the compiler is confusing it with the…
-
4
votes2
answers988
viewsA: Parse a txt file
Because it is a configuration file I would recommend you to use a file of type .ini, but unfortunately Java does not have a standard library to do this kind of operation, if you agree to do so you…
-
9
votes1
answer5689
viewsA: Difference between hours greater than 24 hours excel
It is a problem in formatting the cell that is storing the result. If you leave the formatting as "number" the cell will display 1,03403 (depending on the number of decimal places you asked to…
-
5
votes1
answer3440
viewsA: How to override equals method?
You have two problems with your code: You have defined static variables for your Student class, meaning that all objects in this class will share the same values for the variables. Remove the static…
-
4
votes3
answers531
viewsA: String.equals and Nullpointerexception method
The difference is that in the first case you are creating an object of type String, whose value is equal to teste. Soon after you call the method equals() of that object. As an argument, you are…
-
7
votes1
answer69
viewsA: Nullpointexception when inserting element in list
One of the problems with code is when trying to add a product to an uninitialized list produtos class Orcamento, to initialize your list you can do so: private List<Produto>produtos = new…
-
4
votes3
answers1175
viewsA: Using Double in the compareTo method
As you can see in the error message: Cannot invoke compareTo(double) on the Primitive type double You’re trying to access a method in a primitive type, but primitive types have no methods, only…
-
17
votes3
answers590
viewsA: Doubt about Inheritance
Because when we cast the class remains the one that was instantiated? First it is important to understand the object difference and reference variable. When doing: Filho filho = new Filho(); You…
-
4
votes1
answer13184
viewsA: assignment list index out of range
Tsup is an empty list and you try to access your first element by doing Tsup[0]. To associate a new element to it the correct one is to use the function append(): Tsup.append(Tsup_i) But note that…
-
6
votes2
answers784
viewsA: printf in Java - What is %3d for?
The explanation of %3d can be divided as below: % prints a variable here, 3 use at least 3 characters to display, filling in spaces if necessary, d the variable is of the int. See a demo on Ideone.…
-
7
votes2
answers238
viewsA: Doubt with recursiveness
What really does it? return n + sum( n - 1); The method sum() keeps calling itself always passing as parameter the very number that received as argument minus one, until that number reaches zero…
-
4
votes3
answers104
viewsA: About inserting names into an array. The user puts the course name as argument in the method
Its first 5 lines containing Cadastre seus cursos aqui. are being printed by the 5 method calls aluno.inserirCurso(). Hence, within this method you fill a variable with the value passed in the…
-
4
votes1
answer376
viewsA: Comparison of Bigdecimal result with Float (Java)
The problem in this case is that you have changed the operators' precedence, and consequently you are getting another value. Simply put, your code is like this: public class Teste { public static…
-
8
votes4
answers3199
viewsA: Check if String is number, if not, return error to user
As it comes to only 3 values, you can make one switch-case for each of the options. It is less costly than making an exception. Code: import javax.swing.JOptionPane; public class Teste { public…
-
8
votes5
answers1643
viewsA: Difference between private and final methods
Declaring a method with the same signature is not the same as overwriting? If you declare methods with the same signature but in completely different classes, this is not overwriting, it is just two…
-
2
votes1
answer1392
viewsA: Get item value in focus on a Jlist?
What you’re looking for is a System that checks when you’ve changed the selected element within your Jlist. You can make your Jlist implement a Listselectionlistener, and overwrite the method…
-
3
votes1
answer3147
viewsA: Use case diagram - include and extend
First of all we need to understand the differences of the two relationships of use cases. Relationship of inclusion This is when a base use case makes use of the extended use case. The base use…
-
4
votes2
answers1883
viewsA: How to remove spaces at the beginning and end of an XLS output
To remove the whitespace before and after the text, you can use the .strip(). To print the special characters, you can put the .encode('utf-8'). To put everything in Lower case, put a .lower() at…
-
8
votes7
answers1690
viewsA: Hexadecimal for RGB
Python def hex_to_rgb(value): value = value.lstrip('#') lv = len(value) return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)) def rgb_to_hex(rgb): return '#%02x%02x%02x' % rgb #…
-
8
votes3
answers29788
viewsA: Measuring the run time of a function
Basically you should take the start and end times of the test and then check the difference. There are several options for how to take a break in Python, such as the functions of the module time,…
-
5
votes1
answer1208
viewsA: Call method when Enter key is pressed
You can add the System directly to Jtextfield at the time it is created. Below that code: writingTextField = new JTextField(); Create the Listener like this: writingTextField.addKeyListener(new…
-
8
votes2
answers8022
viewsA: Convert String to Date
Create a Simpledateformat object by initializing the date format according to how your String is formatted, then just parse the String and play in a Date. See the code: import…
-
10
votes3
answers434
viewsA: What is the maximum value for javascript number?
In the JS this representation happens like this: Number.MAX_VALUE And its value is approximately 1.79E+308. That is, 179 followed by 306 digits. See the code:…
javascriptanswered Math 30,313 -
3
votes2
answers2241
viewsA: Exit loop when string is empty or when typing a specific word
First, each do must have only one while and not two equal is in your code. To fix this you could for example do the two checks within one while only using a conditional operator. Example: while…