Given a int variable named yesCount and another int variable named noCount and an int variable named response write the necessary code to read a value into into response and then carry out the following: if the value typed in is a 1 or a 2 then increment yesCount and print out "YES WAS RECORDED" if the value typed in is a 3 or an 4 then increment noCount and print out "NO WAS RECORDED" If the input is invalid just print the message "INVALID" and do nothing else. ASSUME the availability of a variable, stdin, that references a Scanner object associated with standard input.

Respuesta :

// This command takes input from the user.

Scanner input = new Scanner(System.in);

int response= input.nextInt();

// Making the variables required

int noCount =0 ;

int yesCount =0;

// Checking the response if it is 1 or 2 and reporting accordingly

if(response == 1 || response ==2){

 yesCount+=1;

 System.out.println("YES WAS RECORDED");

}

// Checking if the input is 3 or 4 then printing the required lines

else if (response == 3 || response ==4){

noCount+=1;

 System.out.println("NO WAS RECORDED");

}

// if the input is not valid than printing INVALID

else{

System.out.println("INVALID");

}