Given that ph refers to a float, write a statement that compares ph to 7.0 and makes the following assignments (RESPECTIVELY!) to the 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

Answer :

ijeggs

Answer:

public class TestClock {

   public static void main(String[] args) {

   float pH=7.0;

   int neutral, base,acid;

   if(pH <7){

       neutral=0;

       base=0;

       acid=1;

   }

   else if(pH==7){

       neutral=1;

       base=0;

       acid=0;

   }

   else if(pH>7){

       neutral=0;

       base=1;

       acid=0;

   }

   }

}

Explanation:

Above is the solution to the problem implemented with Java programming language

  1. Create a variable called pH and initialize it (Note your code can also prompt a user to enter a value for this variable.
  2. Use if/elseif statements to check for the conditions as given in the questions and do all assignments as required

Following are the code to the given question:

Program Explanation:

  • Defining a variable "ph" that inputs an integer value.
  • Defining a conditional statement that checks ph values that can be defined as follows:
  • In the if block, it checks the "ph" value less than 7, when it's true it assigns the value in "neutral, base, and acid" which is "0,0, and 1".
  • In the elif block, it checks the "ph" value greater than 7, when it's true it assigns the value in "neutral, base, and acid" which is "0, 1, and 0".
  • In the else block, it assigns the value in "neutral, base, and acid" which is "1,0, and 0".
  • In the last, the print method that prints the value.

Program:

ph=int(input("Enter ph value: "))#input ph value

if ph < 7:#defining if block that checks ph value less than 7      

   neutral = 0#holding value in neutral variable    

   base = 0#holding value in base variable    

   acid = 1#holding value in acid variable

elif ph > 7:#defining elif block that checks ph value greater than 7    

   neutral = 0#holding value in neutral variable    

   base = 1#holding value in base variable    

   acid = 0#holding value in acid variable

else:#else block    

   neutral = 1#holding value in neutral variable    

   base = 0#holding value in base variable    

   acid = 0#holding value in acid variable

print(neutral, base , acid)#print value

Output:

Please find the attached file.

Learn more:

brainly.com/question/15244944

${teks-lihat-gambar} codiepienagoya
${teks-lihat-gambar} codiepienagoya
${teks-lihat-gambar} codiepienagoya

Other Questions