Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

Fred Kleinschmidt

Bartender
+ Follow
since Oct 13, 2015
Retired after 45 years as software engineer (Computational Fluid Dynamics) at the Boeing Company.
Seattle, Washington, USA
Cows and Likes
Cows
Total received
10
In last 30 days
0
Total given
0
Likes
Total received
153
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Fred Kleinschmidt

Presumably sc is a Scanner. So sc.nextLine() returns a String from that scanner.
"Double" is a Java class; it has a static method called parseDouble.
Static methods are called using the form "ClassName.methodName()".
So Double,parseDouble( Strikng string ) is invoking the Double class static method which takes a String as its argument and returns a double value if the string can be interpreted as representing a double value, or it throws an exception if the string does not represent a double value.
4 months ago

Which of the alternatives is correct?

Which one do you think is correct, and why? Why do you think the others are incorrect?
4 months ago
One way without switch is to not include the same test condition when unnecessary:
4 months ago

The program repeats until the input string is quit 0.


This means, to me, that it should exit only if the input is "quit 0"
5 months ago
In addition to what Stephan wrote, do you know what a tree is? What is the difference between a node and a leaf?
And the given solution assumes that the zeroth entry in the array is an object of type Integer. It should not be cast to Integer without first assuring that such a cast is legal.

An Object[] is a very poor choice to implement a tree.
5 months ago
Actually, if you are only using %s as the format (and not something more complicated, for example for real  number formatting) I would just use:

It is easier to read, and easier to modify if needed.
5 months ago
Get rid of the second % in each specifier., ...
for example,

For selecting based on probability, generate a random integer between 1 and 100 inclusive.
Then if the value is in the range 1 to 10 (10 %), select "Bad".
If it is between 11 and 70 (60 %), pick "normal".
If it is between 71 and 90 (20 %), pick "good".
Otherwise (i.e., from 91 to 100) (10 %), choose "Excellent".
5 months ago
You do not need to use pow() to solve this. Each square contains twice the previous value.

The first square contains f(1) =2^0=1, the second contains f(2) = 2^1=2 = 2*f(1), the nth contains f(n) = 2^(n-1) = 2 * f(n-1)  so the 64th square contains 2^63.

As Campbell Ritchie pointed out, this is larger than will fit in an int or long (The maximum ling is 2^63 - 1).
5 months ago
You haven't said what your difficulty is. Is it  not working? If not, what is it doing instead of what yu want?

Note that you should never delay or sleep inside a method that is executed on the EventDispatchTread.
5 months ago
Using the terms "Parent class" and "Child class" is a poor choice of terminology. One should use "Superclass" and "Subclass" instead.

"Parent" and "Child" are usually used  to describe GUI relationships.
For example, when you add a JLabel to a JPanel, the panel is the parent of the label, and the label is a child of the panel (see java.awt.Component.getParent()).
So the label is a child of the panel, but it is not a subclass of JPanel.

Similarly, if you create a new class MyLabel that is a subclass of JLabel, and add a myLabel to the JPanel, the myLabel's parent is the JPanel. JLabel is the superclass of MyLabel, not its parent.
5 months ago
Note that
27%26 = 1
and
26%26 = 0
So you will need to handle the case where the answer is zero differently if you want the answer to be 26.
5 months ago
Also, the do-loop ending at line 83 with this criterion: seems to be an infinite loop with no break statement
5 months ago
In general, it is easier to solve if you rotate both boxed so that they lie flat in the x-y plane, where it is easier to calculate the volume of each. Then see if the one with the smaller volume will fit in the larger box.
6 months ago

if((month == 1 || month == 3 || month == 5 || month == 7 ||
          month == 8 ||month == 10 || month == 12 )||day<=1||day>=31){
          _day=day;}


If the user enters 0 for day, this line will set _day to 0 regardless of the month.

Perhaps you mean to use something like

6 months ago
You never compare second and third (your third if-statement is incorrect).

Here's one way to do it:
7 months ago