Ask Question

Write an expression that attempts to read a double from standard input and store it in an double variable, x, that has already been declared. This expression's value should be true if the attempt was successful but false if no data was read because there was no more data available.

+1
Answers (1)
  1. 6 October, 12:35
    0
    x = scan. nextDouble ();

    if (x = = Math. floor (x)) {

    System. out. println ("False. The number is not a double");

    } else {

    System. out. println ("True. The number is a double");

    }

    Explanation:

    First,

    x = scan. nextDouble ();

    allow the receive input to be assigned to the already declared x.

    The next block of if-else statement evaluate to true or false depending on if the number entered is a double or not.

    The if statement check if the flooring of x is the same as x, if it is, then the number is not a double else if they are not the same the it is a double.

    The flooring of a number remove the decimal part of the number and the decimal part of the number is what define a number as double.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write an expression that attempts to read a double from standard input and store it in an double variable, x, that has already been ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers