Ask 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, 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:

+2
Answers (2)
  1. 21 March, 02:21
    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;

    }

    } }
  2. 21 March, 02:21
    0
    Their answeres choices
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 & 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