155k views
2 votes
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".

User Thorinkor
by
5.4k points

1 Answer

3 votes

Answer:

The code to this question can be given as:

Code:

int callsReceived,operatorsOnCall; //define variable as integer

Scanner ob= new Scanner(System.in);

//create object of scanner class for user input

System.out.println("Insert the value of callsReceived"); //print message.

callsReceived = ob.nextInt(); //input value.

System.out.println("Insert the value of operatorsOnCall"); //print message.

operatorsOnCall = ob.nextInt(); //input value.

if (operatorsOnCall == 0) //check number

{

System.out.println("INVALID"); //print message.

}

else

{

System.out.println(callsReceived/operatorsOnCall); //print value.

}

Explanation:

In the above code firstly we define 2 integer variable that name is already given in the question. Then we create the scanner class object for taking user input. Then we print the message for input first and second value from the user. then we use conditional statement. If the second variable that is operatorsOnCall is equal to 0. So It print INVALID. else it divide the value and print it.

User Danirod
by
5.4k points