Alternative code

Report a typo

Comments can not only be used to explain code, but also sometimes when a programmer wants to temporarily disable some code in the program (for example, to try alternative implementations).

Here is an example of a program, where you need to define the lines that must be commented out in order for the program to correctly calculate the result of addition and subtraction of two variables x and y with values 30 and 20 respectively.

Fill in the gaps with the relevant elements
public class Calculator {
  public static void main(String[] args) {
    int x = 30;
     int y = 10;
    int y = 20;

     System.out.println("Sum: " + x + " + " + y + " is " + x + y);
    System.out.println("Subtraction: " + x + " + " + y + " is " + x - y); 
    System.out.println("Sum: " + x + " + " + y + " is " + (x + y));
    System.out.println("Subtraction: " + x + " - " + y + " is " + (x - y));
  }
}
/**//////**

Create a free account to access the full topic