Computer Science, asked by alivia07, 11 months ago

Set of questions of increment and decrement operators in java ( write ans in bracket ) ( atleast 50 questions )​

Answers

Answered by nilesh102
1

hi mate,

Answer :

Increment and Decrement Operators in Java

  • Increment and decrement operators in Java are also known as unary operators because they operate on a single operand. The increment operator (++) adds 1 to its operand and decrement operator (–) subtracts one.

  • Operator Meaning
  • ++ Increment Operator
  • — Decrement Operator

  • Syntax:-

  • ++variable; // pre increment operator
  • variable++; // post increment operator
  • --variable; // pre decrement operator
  • variable--; // post decrement operator

  • Expression The initial

  • The final
  • value of a Value x
  • x = ++a 4 5 5
  • x = a++ 4 5 4
  • x = –a 4 3 3
  • x = a– 4 3 4

  • Increment operators (++)

  • First, the value of the variable a incremented by 1 and store in the memory location of variable a.
  • Second, the value of variable a assign to the variable x.

  • class PreIncrementOperator{

public static void main

(String[] args) {

int a, x;

a = 10;

x= ++a;

System.out.println("a: "+a);

System.out.println("x: "+x);

}

}

  • Output:-
  • a: 11
  • x: 11

  • Decrement Operators ( -- )
  • Pre-decrement operator in Java ( --a )

  • First, the value of a decremented by 1 and store in the memory location of variable a.
  • Second, the value of the variable a assigned to the variable x.

  • class PreDecrementOperator

{

public static void main(String[] args) {

int a, x;

a = 10;

x = --a;

System.out.println("a: "+a);

System.out.println("x: "+x);

}

}

  • Output:-
  • x: 9
  • y: 9

i hope it helps you.

Answered by HariesRam
13

Answer:

1.Java Interview program on pre increment operator.

  1. package com.instanceofjava;
  2. class IncrementDemo{
  3. public static void main(String [] args){
  4. int a, b;
  5. a=10;
  6. b=++a;
  7. System.out.println(b);
  8. }
  9. }

Output:

  1. 11

2.Java Interview program on post increment operator.

  1. package com.instanceofjava;
  2. class IncrementDemo{
  3. public static void main(String [] args){
  4. int a, b;
  5. a=10;
  6. b=a++;
  7. System.out.println(a);
  8. }
  9. }

Output:

  1. 11

❤️

Similar questions