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

Respuesta :

ijeggs

Answer:

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

ACCESS MORE