Question: CHALLENGE ACTIVITY 3.16.2: Conditional expression: Print negative or positive. Create a conditional expression that evaluates to string negative if userval is less than 0, and


CHALLENGE ACTIVITY 3.16.2: Conditional expression: Print negative or positive. Create a conditional expression that evaluates to string "negative" if userval is less than 0, and "non-negative" otherwise. Ex: If userval is -9, output is: -9 is negative. 1 test passed All tests passed 1 import java.util.Scanner; 2 3 public class NegativeOrPositive { 4 public static void main (String [] args) { 5 Scanner scnr = new Scanner(System.in); 6 String condStr; 7 int userVal; 8 userval = scnr.nextInt(); 10 11 condStr - \* Your solution goes here */; 12 13 System.out.println(userval + " is " + condStr + "."); 14 } 15 } 9 Run Feedback? CHALLENGE ACTIVITY 3.16.3: Conditional assignment. Using a conditional expression, write a statement that increments numUsers if update Direction is 1, otherwise decrements numUsers. Ex: if numUsers is 8 and update Direction is 1, numUsers becomes 9; if update Direction is 0, numUsers becomes 7. Hint: Start with "numUsers = ...". 1 test passed All tests passed 1 import java.util.Scanner; 2 3 public class UpdateNumberOfUsers { 4 public static void main (String [] args) { 5 Scanner scnr = new Scanner(System.in); 6 int numUsers; 7 int updateDirection; 8 9 numusers = scnr.nextInt(); 10 updateDirection = scnr.nextInt(); 11 12 /* Your solution goes here */ 13 14 System.out.println("New value is: + numUsers); 15 } 16 } Run Feedback? How was this section? 10 q1 Provide feedback
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
