Note: in mathematics, division by zero is undefined. so, in java, division by zero is always an error. given a int variable named callsreceived and another int variable named operatorsoncall write the necessary code to read values into callsreceived and operatorsoncall and print out the number of calls received per operator (integer division with truncation will do). however: if any value read in is not valid input, just print the message "invalid". assume the availability of a variable, stdin, that references a scanner object associated with standard input. submit

Respuesta :

Here you go,


callsReceived = stdin.nextInt();

operatorsOnCall = stdin.nextInt();

if (operatorsOnCall == 0)

System.out.println("INVALID");

else

System.out.println(callsReceived/operatorsOnCall);

Answer:

The following solution presume availability of a variable, stdin, that references a scanner object associated with standard input.

  1.        int operatorsoncall;
  2.        int callsreceived;
  3.        System.out.print("Enter call received: ");
  4.        callsreceived = stdin.nextInt();
  5.        System.out.print("Enter number of operators on call: ");
  6.        operatorsoncall = stdin.nextInt();
  7.        if(operatorsoncall ==0){
  8.            System.out.println("Invalid");
  9.        }else{
  10.            System.out.println("Number of call received per operator: " + callsreceived/operatorsoncall);
  11.        }

Explanation:

Let's declare two required integer type variable, operatorsoncall ad callsreceived (Line 1 & 2).

We can use stdin object method, nextInt() to read an integer given by user and assign it to operatorsoncall ad callsreceived, respectively (Line 5 & 7).

Since the division by zero is an error, the value of operatorsoncall must not be zero. By presuming this program is only to handle division by zero error, we can set a condition if the read value held by operatorsoncall is zero, print a message "Invalid" (Line 10). Otherwise, the program will display the number of call received per operator (Line 12).

ACCESS MORE