Ask Question

Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the bool variables neutral, base, and acid: a. false, false, true if pH is less than 7 b. false, true, false if pH is greater than 7 c. true, false, false if pH is equal to 7

+2
Answers (1)
  1. 13 August, 08:38
    0
    public class PhTester {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("What is the pH Value");

    double pH = in. nextDouble ();

    boolean neutral, base, acid;

    if (pH<7.0)

    {

    neutral=false;

    base=false;

    acid=true;

    }

    else if (pH>7.0)

    {

    neutral=false;

    base=true;

    acid=false;

    }

    else if (pH==7.0)

    {

    neutral=true;

    base=false;

    acid=false;

    }

    }

    }

    Explanation:

    A complete java code is given above:

    1. the variables neutral, acid, base are declared as booleans

    2. Scanner class is used to request the user to enter a value for the pH

    3. If/else statements are used to assign values to the variables
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the bool variables neutral, ...” 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