Ask Question
27 November, 11:48

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.

+5
Answers (1)
  1. 27 November, 15:04
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers