Ask Question
Today, 14:02

Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the int variables neutral, base, and acid: 0,0,1 if pH is less than 7 0,1,0 if pH is greater than 7 1,0,0 if pH is equal to 7 History:

+1
Answers (2)
  1. Today, 14:08
    0
    Their answeres choices
  2. Today, 14:59
    0
    if (pH<7.0) {

    neutral=0;

    base=0;

    acid=1;

    }

    else if (pH>7.0) {

    neutral=0;

    base=1;

    acid=0;

    }

    else if (pH==7.0) {

    neutral=1;

    base=0;

    acid=0;

    }

    Explanation:

    As required by the question, if and else statements have been used to test the value of the pH and assign the apropriate values to the variables neutral, base and acid.

    The code snippet below can be used to prompt the user to enter values for pH

    import java. util. Scanner;

    public class pHTest {

    public static void main (String[] args) {

    Scanner scr = new Scanner (System. in);

    System. out. println ("Enter a value for the pH");

    int neutral, base, acid;

    double pH = scr. nextDouble ();

    if (pH<7.0) {

    neutral=0;

    base=0;

    acid=1;

    }

    else if (pH>7.0) {

    neutral=0;

    base=1;

    acid=0;

    }

    else if (pH==7.0) {

    neutral=1;

    base=0;

    acid=0;

    }

    } }
Know the Answer?
Not Sure About the Answer?
Get 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 int variables neutral, ...” 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