7,116 Posted Topics
Re: Create the random data run the sort and see how long it takes now run the sort again - this time the data will already be sorted - and see how much quicker that is | |
Re: [edit] ; see invisal's post below for a better explanation of loop problem 100000.0 is a double constant, so the aithmetic is done in double precision, then you assign it to a float and potetially loose precision. Nowdays there's no real reason to use float ever - the precision is … | |
Re: One way to parse lines like that is to use String's `split` method with a one-or-more-blanks regex as the delimiter | |
Re: Do you mean stuff like this (class name changed, comments deleted) to make it less obvious) public class QQQ<E> extends Vector<E> { private static final long serialVersionUID = -1859832140413652455L; private Comparator<E> c; public QQQ(Comparator<E> c) { this.c = c; } public QQQ() { // no comparator: behaves like Vector c … | |
Re: Welcome to Java 8! That code seems to have acumulated some extra code, presumably from trial-and-error. I took your code, added a litte constructor to Order, and set up some test data like this List<List<Order>> list = new ArrayList<>(); List<Order> list1 = new ArrayList<>(); List<Order> list2 = new ArrayList<>(); list1.add(new … | |
Re: 16 bytes is 16 bytes. How you read them depends on what they represent and what you want to do with them. What are these bytes? Are they a signed, big-endian 16 byte integer value, or what? Knowing where they come from may help. | |
Re: I don't have a JDK here, but if I remember right you are setting the weights to 1 for the text areas and 0 for the buttons, so all the available space is allocated to the areas | |
Re: If you simply take every block of code iside those loops/ifs that is more than 3 lines long and put those in separate well-named methods then you will be able to see your overall logic flow properly | |
Re: Yes, but tag it UML as well. (I'm a huge fan of sequence diagrams as a tool for allocating responsibilities to classes, especially as a group activity around a whiteboard). | |
Re: That's how arrays work! You have to know the size to create the array. Java comes with things called Lists, that you can create with no entries, then add as many entries as you want. They automatically expand and contract to fit the data. That's what you would normally use … | |
Re: Not a character array! Split gives you an array of Strings, each containing one word, which is exactly what this project needs. | |
Re: what exactly happens when you try to execute it? Do you get any error messages? If you start your main method with a println does that print? If you print the value of n just after line 9 what does that show? | |
Re: It's your choice. Checked means that any method that calls your method had to deal with the exception somehow. Unchecked means the calling method doesn't need to do anything, but if you do throw the exception then expect the application to crash. Which you chose depends on how likely the … | |
Re: Anonymous classes are good if they are small, but if they are more than few lines the code gets hard to read, in which case a named inner class is better. (See how I avoided mentioning lambdas there?). | |
Re: Hi Rahul If you do chose to fix people's homework before them then please take the time to explain what you have changed and why you changed it as you did. Otherwise how will they learn? ![]() | |
Re: Use a Scanner to read the users input. If you read a single char you can compare it in an if test, but you need quotes round the constant, eg char in = ... If (in == 'K') ... | |
Re: You are supposed to read everything in once at the start of the program. Once it's all in the hash maps you can use their get methods to search them and retrieve the requested results for as many requests as you want. | |
Re: Write file seems to be doing some ordering, despite the instructions. Read file seems a bit convoluted. If you can assume that the file does just contain ints then you can read it as strings, split that, then convert to ints. Alternatively ( which I would prefer) create an int … | |
Re: You can just paste the code in Code tags as part of your post. Experience shows that most people won't bother/dare to open a file attachment anyway. | |
Re: Seems like the server is running on a machine that does not have that class in its classpath | |
Re: Never used it myself. GridBagLayout does everything I need, and I have a strong dislike of using third-party anythings unless I have to. | |
Re: FYI: That little pattern on lines13-17 is so common that Java 8 Map has a new `getOrDefault` method to make it simpler. values.put(i, values.getOrDefault(i, 0) +1); | |
Re: A binary search partitions top/bottom halfs, then does the same for the appropriate half and continues until it's found the result. That is a recursive algorithm. It would be natural to implement that with recursive code. However, it's possible to write the code without using recursion, ie an iterative version, … | |
Re: 2 times 3 is 2+2+2 5 times 4 is 5+5+5+5 see a pattern? see how that can be implemented with a loop? | |
| |
Re: Have you bothered to Google, or did you think it was OK to just come here and demand that someone does it for you? | |
Re: Now you have the Method object you can call it by using Method's `invoke` | |
![]() | Re: It's a standard feature of the Java API, See https://docs.oracle.com/javase/tutorial/essential/io/walk.html |
Re: DaniWeb Member Rules (which you agreed to when you signed up) include: "Do provide evidence of having done some work yourself if posting questions from school or work assignments" http://www.daniweb.com/community/rules Post what you have done so far and someone will help you from there. | |
Re: He's right. Think about it. What is the result of` 5/100 `in integer arithmetic? | |
Re: Most bad web sites are not bad because of some technical failure, they are bad because they don't do what the user wants or expects. Learning PHP or whatever is not hard - just takes a bit of time and effort. IMHO the key skill is being able to see … ![]() | |
Re: Copuld be a while or a do/while. Sometimes that's just a question of preference. Try coding both and see which gives the simplest code in your specific application. | |
Re: It will work if you override toString correctly. Check that tyour method signature is correct, ie @Override public String toString() { return <some String expression>; } | |
Re: ` RegistrationDetails registrationDetails = new RegistrationDetails(name);` creates a new instance, and initialises the `name` field, but ` RegistrationDetails registrationDetails = new RegistrationDetails();` creates a new instance and leaves the name field uninitialised (null) The fix is to call getName() using the same instance that you created with a name | |
Re: Use the JTextField's setText method to display the clicked count. You can do that as part of your jButtonScanActionPerformed method | |
Re: Looks reasonable to me - except I don't see why you have a panel (line 5) with only one thing in it - just add the text area directly. For the event handlers on those keys you will DEFINITELY want to use the parametised handler technique from your previous project. … | |
Re: Have a look at Java's `exclusive OR `operator - it's just what you need. | |
Re: OK Bobby. You posted an entire project requirement doc (I hope you own the copyright to that!). Why? What response do you expect? | |
Re: OK Get a grip. Ask one sensible question, and show some effort if you want help. | |
Re: IF you really do have a lot of drawing that is repeated without being changed and if that is consuming a significant amout of resources, then yes, there MAY be an advantage in pre-rendering it. If so, just create a `BufferedImage`, and call its `createGraphics()` to get a `Graphics2D` that … | |
Re: First, some notes on your question: You can't assign a method to an ordinary variable; you assign the result of calling that ethod. You can't call variables, just methods. The code you posted is not a constructor, it's jst an instance variable with an initialiser. Anyway... The Calculation `a` is … | |
Re: If you tage your topic "Java" then it will be seen by many more Java experts who can help you. | |
Re: "It doesn't work" tells us nothing. Would you take your car into the workshop and just say "there's something wrong with it" and expect the mechanic to fix it? Did it compile? Was there an error message? Did the output differ from what you expected, if so in what way … | |
Re: Without actual code one can only make wild guesses, for example: When you copy the populations is that a shallow or a deep copy? Maybe its a shallow copy and subsequent changes to members are affecting both copies? | |
Re: I would also avoid that tutorial site. Seems to have been written by someone whith limited knowledge and no experience of Java. Eg One almost the first page I looked at I found: variable names like `email_address1` use of `Boolean` rather than `boolean` and (where isMatch is a Boolean)... `if … | |
Re: Agreed. BufferedImage was OK as it was, so there was no need to replace it. It's still the one to use. |
The End.