82.1k views
5 votes
Given a double variable named areaofsquare write the necessary code to read in a value , the area of some square, into areaofsquare and print out the length of the side of that square. however: if any value read in is not valid input, just print the message "invalid". assume the availability of a variable , stdin, that references a scanner object associated with standard input.

1 Answer

1 vote
I can solve it with Java. Here it is:

areaOfSquare = stdin.nextDouble();
double sqrt = Math.sqrt(areaOfSquare);
if(Double.isNaN(sqrt)){
System.out.print("INVALID");
} else {
System.out.print(sqrt);
}
User Cigien
by
8.5k points