JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe the problem is that choice is still zero after a failed nextInt(), thus exiting the loop.
Try setting choice to some other vaue (eg -99) in the catch.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is presumably all about passing params as references rather than values (the default in C#)
To pass a parameter as a reference use the ref keyword.
See https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/passing-parameters

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think that sos's point was that you shouldn't have to perform that kind of cast. It probably results from a bad design decision.
The "correct" solution is to declare the List(s) appropriately with a ? extends ...

In this particular case the Lists on lines 17 and 21 shoud be declared as ArrayList<? extends Drawable> so the intent is perfectly obvious, and no cast is needed

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

HashSet<Object> or. HashSet<>. or just HashSet will allow any kind of object. Primitives will be automatically wrapped with the appropriate class.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, one of the easiest ways to detect duplicates is to use a Collection that does not allow duplicates, eg HashSet. Its add method returns false if the set already contains that element.

Nymphalys08 commented: Thank you JamesCherrill.. Can we use hashset even if we have different types in the class?? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hint: Count the steps while traversing the list until encountering position p

isnt it put the method Iterable positions();?

Yes. Simply use positions() to loop through the elements incrementing an index and and test each until you find the one you want. Then return its index.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where do you add the JPanels to the JFrame????

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

JavaDB is just Derby, which moved from Oracle to Apache where it is still very much alive.
The most recent release was March 1st 2021 (!)
https://db.apache.org/derby/

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Recognise that best AND easy doesn't exist.

Oracle's own tutorials are (IMHO) the best - start here

As for easy - there are loads of beginner tutorials on the web - mostly out of date and often downright wrong - but OK if you just want a warm fuzzy hand-holding kind of intro.

Once you get past the "hello world" stage you need to think about what aspects of Java are more important to you - desktop GUI, database, web server etc. The whole of Java takes a lifetime to learn, so you'll need to focus.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your while test is wrong... while grades<= zero AND >= zero.
Grades can't be both those at the same time (unless it is == 0), so the test is false and the loop never gets executed.
Because the loop isn't executed you never increment count, so that stays at zero.
Then when you try to print the average you divide by count and thus get a zero divide exception!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You should explain EXACTLY what "does not work properly" means... eg what error message do you get, or how does the output differ from what you expected.

Anyway - for the moment I notice that you have grades= nextInt(); in 3 places and after two of those you never use that value of grades. That means you are ignoring 2/3 of the ints in the file.
You also include the last (end of file) value in your calculations.
And your calculation of the average (a) will cause a zero divide on its first pass and (b) is wrong anyway.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... and what is your question?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All you NEED is the Java Development Kit (JDK) and a text editor (any text editor).
IDEs like Eclipse and NetBeans are used by real programmers because they provide all kinds of integrated productivity tools BUT they come at the cost of a huge learning curve.
You will find it really hard to learn Java and an industrial-strength IDE at the same time.

My advice would be to:
Start with just the JDK and a simple editor, concentrate on Java basics first.
When you're ready, try an IDE designed for beginners such as Dr Java or BlueJ.
When your programs get into thousands of lines of code, think about Eclipse or NetBeans. Personally I would prefer NetBeans for pure Java and Eclipse for complex multi-language environments, but in the end you will do best with whichever toolset the people around you are using.

How to create a deskto app? You will find hundreds of web sites offering to teach you. Many are written by idiots who don't know how little they understand. Many others were great when they were written but are now years out of date. In my opinion the only one you can trust is Oracle's own Java Tuorials. You could start here

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need something like (pseudo code)

while there is more input available
    read coordinates i and j
    M[i][j] = 1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First, those are two completely different concepts.

Overloading is a convenience thing. Use it when you have a method that could be used with different paameters, eg an internet thing that could use an IPV4 or IPV6 address. You could have two methods with slightly differenet names, but the code will be clearer if you have the same name but different parameter types. It's also useful when you have some optional parameters, eg waitFor(something) and waitFor(something, timeout).

Overriding happens when you have a sublass that needs a different implementation of a method from its superclass. When that is needed its usually obvious.

sonalid1701 commented: Are there any sources where I can practice problems specifically related to these two concepts, to deepen my knowledge about it. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm trying to run VirtualBox in Ubuntu.

The full report shows that you are running WIndows 7, not Ubuntu.

(and... you are running an OS that's past end-of-life support with both the firewall and the anti-virus turned off.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why make this so complicated?

Problem: VT-x is disabled.
It;s suported by the CPU
It's supported by the motherboard
He just needs to enable it in the BIOS. Here are the instructions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You use the new shuffled array to provide N index values in random order. You use those index values to index into all the other arrays.
In other words - on line 7 above you set x to be the next value in the shuffled array of indexes.

Pocokos commented: Could you please give me an example of how that would look? +0
Biiim commented: Yours was a much simpler solution! +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It looks like the file named on line 29 doesn't exist, or is in some incompaible format.

Check out the Oracle documentation at https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html

in particular red the section headed "Resources, names, and contexts"

java_marvin commented: Thank you for this post. I was just looking for something like this. With a few corrections and additions it workes as expected. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's a reasonable start. Some errors to fix, and some functionality to implement. What's your question?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's going to map pretty closely to the Java equivalents, so whats stopping you?

ps: That multi-line string delimited by triple quotes had no equivalent in Java until Java 14 or 15, so make sure you are on the latest version.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

?
If you just have 1 thread, using an executor or not, then there's no concurrency issue.
If you create two thread instances with the same FutureTask instance and start() them simultaneously then you are open to concurrency problems. I can't think of any reason why someone would do that in real life.

It's not clear exactly what your question is. Can you try asking it another way?

ps: there' a reason why the unsafe class is called unsafe. It's not safe.
I would want to see a code review by at least two experienced coders confirming that it is essential and the only way to meet the business spec before allowing its use

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You may have Java 15 installed, but according to your screenshots, you are using Java 8

It's more bizarre than that. The java version is 1.8 but the compiler is 1.15
Possible reason is that a 1.8 JRE (runtime only) was installed, followed later by a 1.15 JDK (full developmen kit), but the JRE is still before the JDK in the PATH, or maybe the JAVA_HOME variable still points to the JRE.

rproffitt commented: That! +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I looked. It's a standard "complete the code" learning exercise.
How far have you got? What have you tried? Exactly what help do you need?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you store it as a 2D array in Java then it's easy.
Remember htat a 2D array is really an array of arrays, so all you need is the check that the length of each inner array is the same as the length of the outer array. No need to count anything. You won't find anything more efficient than that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi

Please post your code in the thread here so pleaple can see it easily. Depending on what your question is you may not need to post the whole thing. Use the code block button (the one after B and I) to format and line number it properly.
Explain exactly what help you are looking for.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I was running on the last couple of Betas, and switched to the release version with no regrets.
The only problem I hit is that NetBeans crashes on startup, but IntelliJ is just fine, so IDC.
M1 for Xmas?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

At line 48 you have eElement so you can use that to test for the ID (or whatever) you are interested in and print or not print accordingly.

abdoosh commented: #JamesCherill thank you very much bro , Done +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What is the "much better technology"?
MacOS - better, but a LOT more expensive
Windows - more popular, but not necessarily better. And again you have to pay for it.

And what's wrong with Linux anyway?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As an IT professional of course I know not to be an early adopter with a production system.

But the man in the street may well have "automatic updates" turned on - in which case he will wake up in the morning with a device full of untested software. Especially when he sees advice like this from Business Insider

It's simply irresponsible behaviour from Apple.

rproffitt commented: Apple, Fortnite, and others are engaging in a battle over control and dollars. We can't ignore that either. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm going with "can be done" - at least in theory

  1. Excel supports 1 million rows
  2. Even London has (only) 32 thousand streets ( https://www.proviser.com/uk/towns/london/street-map )
  3. Some streets in London have 2 or more names ( https://www.maps.thehunthouse.com/Streets/New_to_Old_London_Street_Name_Changes.htm )
rproffitt commented: Algeria is a country so there's that. However this question has been done many times and what follows is usually a spammer reply. +0
BreighA commented: Thank you for reply. :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Re IOS GM/release

The reason developers are upset is that every major release breaks something, and until you have the GM you cannot test for regression bugs or other problems. Ie: users are updating to an OS for which you have not been able to perform proper testing of your app.
I;ve been deluged with emails for production apps that I use advising me not to update to 14 until they have completed testing and released (got through Apple Store's release process) updated versions as necessary.

It's not about heving new features on day 1, it's about having an app that continues to work.

rproffitt commented: Thanks James for the clarification. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Interesting
I wait months for a Java question, but I'm not a "Suggested Answerer".
Guess I must be really out of favour at DaniHQ.
Or maybe it's just that I'm too old (2019 years old according to my profile).

rproffitt commented: One more year and you'll join The Old Guard. +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I just finished writing them. Now what?

Abdul_68 commented: you can share them right +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you have enough address space for 10 biilion long long ints (at least 80GB)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thanks for formatting the code, and yes, you're right.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's commendable that you took the time to reply. However, the topic title and the origional post clearly asks for a discussion of 2-dimensional array as argument, and the content you posted covers declaration, referencing, and initialisation, but does not address that question.

AndreRet commented: I came to realise the same, my apologies for jumping to conclusions, the error was from my side. +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hard to read with no indentation, but it looks like the function at line 27 has its return statement inside an if test, so if the if test fails control will evntually drop through to line 35 where the function finishes without having returned an int.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

voogos

what you are discussing is called cheating. Lie to your teachers, degrade the efforts of your honest colleagues who actually do the work, waste the chance to learn for yourself, deceive uourself and others about your abilities...
What do you do in your spare time? Rob grannies?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, that's true... but did you have any particular reason for sharing that today?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Following on from fearless' suggestion...
I'm not sure about Python, but this looks like a using a factory, Typically that's for a constructor, but there's no reason not to use it for any complex method call.
Eg: suppose it's a car search where you can supply manufacturur, engine size, fuel, number of seats, age, min price, max price etc and all those are optional. Use a search builder that starts with defaults for everything, has methods to override each default, and an execute method. The execute method calls the real search with all the possible parameters set.
All the methods(except execute) should return the search object so they can be chained,
Using it looks like (pseudo code):
result= new CarSearch().fuel(electric).maxPrice(20000).execute();
or
result= new CarSearch().manufacturer(Ford).seats(7).execute();
Personally I'm a big fan of this approach.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Welcome. Your English is amazing!

stefh commented: Thanks a lot! It encourages me, because I always woder if my english is understandable... According to you, it seems so! Thank you very much! :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. I'm doing this in 2D to save typing. For 3D just add a Z value.

You are at a point X,Y moving in a straight line. That means that at some regular interval you add something to X and Y. Let's call that a step. A step tells you how much to change the X and Y values by. Let's call those stepX and stepY. It's a loop hat looks like

do (at an interval of some milliseconds) {
       X = X + stepX;
       Y = Y + stepY;
 }

How fast you move along that line depends on (a) how often the loop runs and (b) how big the step is. Normally you would loop about 30 times per second for a smooth motion and reasonable CPU usage. So its the step that you change.

Suppose we are going from X1,Y1 to X2,Y2 and we want that to take 5 seconds - ie 150 times through the loop. The step .has to be

  stepX = (X2 - X1)/150;
  stepY = (Y2 - Y1)/150

ps: if you do this in integer arithmetic you'll hit all kinds of rounding problems. Make the variables doubles precision float.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You cannot add a speed and a vector. They are different measures. It's mathematically impossible, like trying to add a length to an area.

You can add a vector, as in

i have X,Y(10,20) and the change is is (2,3) , the addition will be:
X = X + 2
Y = Y + 3

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Which comment are you referring to and what info do you want to remove? There are situations in which a mod can edit for you, provided it's covered by the DaniWeb rules.

Yusuf_13 commented: i got it deleted by a moderator +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your answer is 9 years too late, adds nothing to the discussion, and is one of the worst pieces of code I have seen in some time. You obviously need to study boolean values some more becuase testing a boolean for true is such a novice mistake.
The whole of your tortuous lines 3 - 10 are just a horrible way to code

btnSave.Visible = chkSave.Checked;
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You have a single quote at the end of line 43.

For the corect syntax of a switch, with examples, see the Oracle tutorial page here

ps: You keep creating new instances of Scanner. That can cause problems with text buffers getting lost. Just create one instance when the program starts, and use that for everything.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How can I check the Java version from command line.

java -version

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can do it. How much are you paying?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's not really any "organisation of values" required in this spec.
You have 4 values as parameters and all the if tests use one or more of those values.
Can you explain your concern in more detail?

Giselle_1 commented: Not to worry, I have solved the problem and managed to create the method. Thank you. +0