Ask Question
23 June, 20:27

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:

+4
Answers (2)
  1. 23 June, 22:20
    0
    Their answeres choices
  2. 23 June, 22:55
    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?
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 int variables neutral, ...” 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