28.3k views
1 vote
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.

1 Answer

4 votes

Answer

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;

}

A complete java program that prompts a user for the pH value is provided in the explanation section

Step-by-step explanation:

import java.util.Scanner;

public class ANot {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

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

boolean neutral, base, acid;

double pH = in.nextDouble();

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;

}

}

}

User Stephen Mallette
by
5.4k points