Question: Need help to condense this code block. public java.lang.String getResult() { this.getArraySum(); if (this.sumOfArray > this.guessTargNumber) { if (this.guess == 'Y') { return You guessed
Need help to condense this code block.
public java.lang.String getResult() { this.getArraySum(); if (this.sumOfArray > this.guessTargNumber) { if (this.guess == 'Y') { return "You guessed correctly! The sum was " + this.sumOfArray + "!"; } else { return "You guessed wrong! The sum was " + this.sumOfArray + "!"; } } else { if (this.guess == 'Y') { return "You guessed wrong! The sum was " + this.sumOfArray + "!"; } else { return "You guessed correctly! The sum was " + this.sumOfArray + "!"; } } }
It needs to be 2 or less returns. Maybe a local variable can be added and used?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
