Computer Science, asked by anunaysrivastava0812, 5 hours ago

write a program to take an integer variable to assign 20 increase the value of variable by 10 using shorthand ooerator display the orignal and increased value​

Answers

Answered by burstbeylocker173
0

Answer:

Shorthand operators

Shorthand operator:

A shorthand operator is a shorter way to express something that is already available in the Java programming language

Shorthand operations do not add any feature to the Java programming language

(So it's not a big deal).

Shorthand operators +=, -=, *=, /= and *=

A frequent construct is the following:

  x is a variable in the program

  x = x + value ;   // Add value to the variable x

  x = x - value ;   // Subtract value to the variable x

  x = x * value ;   // Increase the variable x by value times      

  and so on...

Java has a shorthand operator for these kinds of assignment statements

Operator assignment shorthands:

Operator symbol   Name of the operator   Example   Equivalent construct  

+=   Addition assignment  x += 4;  x = x + 4;

-=   Subtraction assignment  x -= 4;  x = x - 4;

*=   Multiplication assignment  x *= 4;  x = x * 4;

/=   Division assignment  x /= 4;  x = x / 4;

%=   Remainder assignment  x %= 4;  x = x % 4;

Exercise: what is printed by the following program

  public class Shorthand1

  {

     public static void main(String[] args)          

     {

    int x;

   

    x = 7;

    x += 4;

    System.out.println(x);

   

    x = 7;

    x -= 4;

    System.out.println(x);

   

    x = 7;

    x *= 4;

    System.out.println(x);

   

    x = 7;

    x /= 4;

    System.out.println(x);

   

    x = 7;

    x %= 4;

    System.out.println(x);

     }

  }

Explanation:

Similar questions