0% found this document useful (0 votes)
94 views3 pages

? Java Worksheet - Increment and Decrement Operators

This document is a Java worksheet focused on increment (++) and decrement (--) operators, designed for Class 9 and Class 10 students. It includes concept review questions, output prediction exercises, coding practice tasks, and challenge questions to enhance understanding of these operators. The worksheet aims to provide a comprehensive understanding of how increment and decrement operators function in Java programming.

Uploaded by

mehtamannan652
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views3 pages

? Java Worksheet - Increment and Decrement Operators

This document is a Java worksheet focused on increment (++) and decrement (--) operators, designed for Class 9 and Class 10 students. It includes concept review questions, output prediction exercises, coding practice tasks, and challenge questions to enhance understanding of these operators. The worksheet aims to provide a comprehensive understanding of how increment and decrement operators function in Java programming.

Uploaded by

mehtamannan652
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

💻 JAVA WORKSHEET: INCREMENT AND DECREMENT OPERATORS

Topic: Increment (++) and Decrement (--) Operators​


Level: Class 9 / Class 10 (ICSE / CBSE)​
Time: 30 minutes

SECTION A — CONCEPT REVIEW (Answer in short)

1.​ What is the purpose of the increment (++) operator in Java?​

2.​ What is the difference between pre-increment (++x) and post-increment (x++)?​

3.​ What is the purpose of the decrement (--) operator?​

4.​ What is the difference between pre-decrement (--x) and post-decrement (x--)?​

5.​ What will be the effect of this statement?​


int a = 5;​
a++;​

6.​ Can increment and decrement operators be used on boolean data types in Java?​

7.​ What is the output of:​


int x = 10;​
System.out.println(x++);​
System.out.println(x);​

8.​ What is the output of:​


int y = 7;​
System.out.println(++y);​
System.out.println(y);​

9.​ Which executes first in post-increment: the value use or the increment operation?​

10.​Which executes first in pre-decrement: the decrement operation or the value use?​

SECTION B — PREDICT THE OUTPUT

Write the output of each of the following code snippets:


1.​ int a = 5;​
int b = ++a;​
System.out.println(a + " " + b);​
Output: ____________​

2.​ int a = 5;​


int b = a++;​
System.out.println(a + " " + b);​
Output: ____________​

3.​ int x = 10, y = 20;​


System.out.println(x++ + ++y);​
Output: ____________​

4.​ int a = 3;​


System.out.println(a++ + a++ + ++a);​
Output: ____________​

5.​ int m = 5, n = 5;​


System.out.println(++m - n--);​
System.out.println(m + " " + n);​
Output: ____________​

6.​ int x = 2;​


int y = x++ + ++x + x++;​
System.out.println(y);​
Output: ____________​

7.​ int a = 10;​


int b = a++ + ++a - --a + a--;​
System.out.println(b);​
Output: ____________​

8.​ int x = 4;​


System.out.println(--x + x++ + ++x);​
Output: ____________​

9.​ int a = 1;​


int b = a++ + ++a + a++ + ++a;​
System.out.println(b);​
Output: ____________​

10.​int p = 5, q = 10;​
q = p++ + --q;​
System.out.println(p + " " + q);​
Output: ____________​

SECTION C — CODING PRACTICE

1.​ Input an integer and display its value before and after pre-increment.​

2.​ Input an integer and display its value before and after post-decrement.​

3.​ Input two integers and print their sum before and after incrementing both by 1.​

4.​ Write a program to show the difference between x++ and ++x in output.​

5.​ Write a program that demonstrates combined increment/decrement operations on a


variable and displays the result.​

SECTION D — CHALLENGE QUESTIONS ⭐


1.​ Predict the output:​
int a = 5, b = 10;​
int c = a++ + --b + ++a - b--;​
System.out.println(a + " " + b + " " + c);​

2.​ What will be printed by:​


int a = 2;​
a = a++ * ++a;​
System.out.println(a);​

3.​ Write a Java expression using increment/decrement operators that evaluates to 15 if int
n = 7.​

4.​ Why is ++(x + y) invalid in Java?

You might also like