K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
Still a beginner at crafting quality coding but have the zeal to learn more. Your help would be appreciated.
My Blog on Learning Analytics
K. Tsang wrote:The problem is with the line
Scanner's nextLine() here is not the correct method to use. Can you figure out which method to use?
Also for lines 8 and 9, does the compiler let you compile without specific the type for the ArrayList??
K. Tsang wrote:
Also for lines 8 and 9, does the compiler let you compile without specific the type for the ArrayList??
R. Jain wrote:The issue is, when you read an input using Scanner#nextDouble() or any Scanner class method reading numeric types, they do not read the linefeed character at the end. And also, it does not advances the Scanner past the current line. So, the next time you read the input using Scanner#next() method, it reads the linefeed. And the input you passed as "y/n", is not read into the "answer" variable. And thus your condition is failed, and "while" loop exits.
And option is to read a blank line after the "input.nextDouble()" like this:
Marixa Garcia wrote:It goes right by the input for name. What am I doing wrong?
R. Jain wrote:
K. Tsang wrote:
Also for lines 8 and 9, does the compiler let you compile without specific the type for the ArrayList??
The syntax is fine for Java 7. It's called diamond operator. In Java 7, you don't need to give the type parameter on the RHS. It is inferred from the one used on the LHS.
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
R. Jain said:
The syntax is fine for Java 7. It's called diamond operator. In Java 7, you don't need to give the type parameter on the RHS. It is inferred from the one used on the LHS.
There are three kinds of actuaries: those who can count, and those who can't.
What's gotten into you? Could it be this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|