Ask Question
6 August, 09:06

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.

+4
Answers (1)
  1. 6 August, 12:40
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers