Write a statement that increases numPeople by 5. If numPeople is initially 10, then numPeople becomes 15.

JAVA.

using the following template:

import java.util.Scanner;

public class AssigningNumberToVariable {
public static void main (String [] args) {
int numPeople = 0;

numPeople = 10;


System.out.print("There are ");
System.out.print(numPeople);
System.out.println(" people.");

return;
}
}

Respuesta :

ijeggs

Answer:

numPeople +=5;

Explanation:

The statement numPeople +=5; increases the value of the variable numPeople by 5, this statement is equivalent to writing numPeople = numPeople +5. As a matter of fact another way of accomplishing this is shown in the code below were we carry out the increament by 5 inside the print statement. See line 7 of the code below.

  1. import java.util.Scanner;
  2. public class AssigningNumberToVariable {
  3. public static void main (String [] args) {
  4. int numPeople = 0;
  5. numPeople = 10;
  6. System.out.print("There are ");
  7. System.out.print(numPeople+5);
  8. System.out.println(" people.");
  9. return;
  10. }
  11. }