Using a conditional expression, write a statement that increments numUsers if updateDirection is 1, otherwise decrements numUsers. Ex: if numUsers is 8 and updateDirection is 1, numUsers becomes 9; if updateDirection is 0, numUsers becomes 7. Hint: Start with "numUsers = ...".

import java.util.Scanner;

public class UpdateNumberOfUsers {

public static void main (String [] args) {

int numUsers = 0;

int updateDirection = 0;

numUsers = 8;

updateDirection = 1;

/* Your solution goes here */

System.out.println("New value is: " + numUsers);

return;

}

}

Respuesta :

Answer:

import java.util.Scanner;

public class UpdateNumberOfUsers {

public static void main (String [] args) {

int numUsers = 0;

int updateDirection = 0;

numUsers = 8;

updateDirection = 1;

   if(updateDirection==1){

       numUsers++;

   }else{

       numUsers--;

   }

System.out.println("New value is: " + numUsers);

return;

}

}

Explanation:

Conditional statement is the statement which used to check the condition, if condition is TRUE then execute the statement otherwise not execute.

if else is the Conditional statement which used in the programming.

According to question, if updateDirection == 1, then increment numUsers , otherwise decrement.

these are the condition which can put in the if else statement:

if(updateDirection == 1)

{

  numUsers++;   //increment

}else{

   numUsers--;  //decrement

}