Questions tagged as 'java'

3
answers

Generate random numbers in an Array of 10 up to 50

How can I generate an array of random numbers with a limit, must be numbers from 10 to 50. To generate random numbers from 0 to 50 I use: Random random = new Random(); int array[] = new int[5]; // 5 números serão ger...
asked by 25.08.2015 / 16:58
3
answers

In what order is a Set stored? Random?

When I store something inside a Set , the order in which it stores is random? And how could I sort a Set ?     
asked by 12.11.2014 / 15:59
4
answers

How to prevent user from entering numbers for a given data?

How do I make my Java program not accept numbers as given by the user? I would like, in a field that requires the user's name, if a number is inserted, such as a badge, do with what program reorder the name. I have already thought of sever...
asked by 14.12.2014 / 00:37
2
answers

Convert milliseconds to hh: mm format in java

I'm doing an Android game with a java engine where it has a Timer that stays all the time running during the Game ... This timer is a millisecond counter and is added in a long. In the end I need to convert this long to a format in hours and...
asked by 29.04.2014 / 07:47
2
answers

Why did println run before printStackTace?

I was studying Java Handling Exceptions and this question came to me that I could not find on Google. Why in this example did he print the first line of printStackTrace, and already gave println, and then the rest of printStackTrace?  ...
asked by 10.05.2017 / 21:14
2
answers

Switch case Kotlin

In Java I use switch in several situations, as in the example below : public class SwitchDemo { public static void main(String[] args) { int month = 8; String monthString; switch (month) { case...
asked by 18.08.2017 / 20:49
4
answers

How to split a string every 2 characters?

I'm trying to split a string every two characters, but I do not have a delimiter and need to use the entire string. Example: String exemplo= 99E65A78 String ex1= 99 String ex2= E6 String ex3= 5A String ex4= 78     
asked by 22.11.2017 / 12:38
2
answers

How do I apply a StyledEditorKit to a JTextPane without having to inherit this class on my screen?

I have a tab problem in JTextPane and I am trying to reduce the default value assigned to it but it is giving an error because I have to inherit two classes (one for JFrame and the other for overwriting the tab functions ) but Java...
asked by 21.10.2016 / 15:30
2
answers

Why this code goes into infinite loop?

Why do I put an invalid entry as asdf the code below goes into infinite loop? After catching the exception and writing the message, should not it ask for another entry again? import java.util.Scanner; public class Leitura { public st...
asked by 04.04.2014 / 05:22
2
answers

Remove String Connectors with Regular Expression

How could I remove connectors: "and", "do", "of", "of", "of", "of", "di", "du". One sentence without changing the whole name. Example name: Daniela de Andrade. I want to remove only "from", without removing the "DA" from andra "FROM" I am usi...
asked by 23.11.2014 / 23:20