0% found this document useful (0 votes)
8 views4 pages

Revision Class 9 IA 1 Operators

The document contains a worksheet focused on prefix and postfix operators in Java, featuring multiple programs that demonstrate their usage. Each program includes a calculation and a question asking for the output, with instructions to show calculations for full marks. Additionally, there are complex examples with multiple operations and expected outputs provided for further practice.

Uploaded by

rohanjhanji2029
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)
8 views4 pages

Revision Class 9 IA 1 Operators

The document contains a worksheet focused on prefix and postfix operators in Java, featuring multiple programs that demonstrate their usage. Each program includes a calculation and a question asking for the output, with instructions to show calculations for full marks. Additionally, there are complex examples with multiple operations and expected outputs provided for further practice.

Uploaded by

rohanjhanji2029
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/ 4

Worksheet on Prefix and Postfix Operators in Java

Program 1
public class Test1 {
public static void main(String[] args) {
int a = 5;
int b = 3;
int c = ++a * 2 - b--;
System.out.println("c = " + c);
}
}

Program 2
public class Test2 {
public static void main(String[] args) {
int a = 6;
int b = 4;
int c = a++ + --b * 3;
System.out.println("c = " + c);
}
}

Q: What will be the output of the above program?

(a) c = 15 (b) c = 16 (c) c = 17 (d) c = 18

[You will not receive full marks if calculations are not shown.]

Program 3
public class Test3 {
public static void main(String[] args) {
int a = 7;
int b = 2;
int c = a % ++b + a-- * 2;
System.out.println("c = " + c);
}
}

Program 4
public class Test4 {
public static void main(String[] args) {
int a = 9;
int b = 5;
int c = --a - b++ + a * 2;
System.out.println("c = " + c);
}
}

Program 5
public class Test5 {
public static void main(String[] args) {
int a = 3;
int b = 8;
int c = ++a + b-- % 3 * --b;
System.out.println("c = " + c);
}
}

Q6 Predict the output

int a = 3;

int b = 9;

int c = ++a + b-- % 4 * --a;

System.out.println("c = " + c);

Q7

int a = 10;

int b = 5;

int c = --a - b++ + a * 2;

q8.

int a = 4;

int b = 7;

int c = a++ % 3 + ++b * 2;

System.out.println("c = " + c);


Q9

int a = 6;

int b = 3;

a = a++ + --b * 2;

q10.

int a = 5;

int b = 8;

int c = ++a * 2 + b--;

System.out.println("c = " + c);

Q11

public class Complex1 {

public static void main(String[] args) {

int x = 5;

int y = 8;

int z = 3;

int result = ++x * (y-- % 4) + z++ - --y;

System.out.println("result = " + result);

What will be printed?


(a) result = 6
(b) result = 7
(c) result = 8
(d) result = 9
Q12

public class Complex2 {

public static void main(String[] args) {

int a = 6;

int b = 4;

int c = 9;

int value = c-- % ++b + a-- * 2 - b++;

System.out.println("value = " + value);

What will be printed?


(a) value = 10
(b) value = 11
(c) value = 12
(d) value = 13

You might also like