Diploma in Information and Communication Technology: Module 3: Control Structure Tutorial
Diploma in Information and Communication Technology: Module 3: Control Structure Tutorial
2. Trace the output for the following statements : a) int a=10; if (a > 5) System.out.println(Hello, good morning); else System.out.println(Good bye); b) int a = 10, b=5; if (a < 2 * b) System.out.print (Hello ); System.out.print (There); c) int x = 100; int y = 200; if (x > 100 && y <= 200) System.out.println (x + + y + + (x+y)); else System.out.println (x+ +y+ +(2 * x - y));
DIPLOMA IN INFORMATION AND COMMUNICATION TECHNOLOGY 3. Trace the output for the following java code segments :
(a)
(b)
DIPLOMA IN INFORMATION AND COMMUNICATION TECHNOLOGY 5. What is the value of alpha after the following Java code segment executed? If alpha has initial value of : (a) 1 (b) 5 (c) 0
6. Trace the output for the following java code segment: (a) j = 2;
for ( i = 0; i<=5; i++) { System.out.print(j + ); j = 2 * j + 3; }
(b)
int x = 5, y = 50; do x = x + 10; while ( x < y); System.out.println ( x + + y);
38 45 71 4 -1
What is the output of the following code ? Assume all variables are properly declared.
(a)
(b)
8. What is the keyword break for? What is the keyword continue for? Will the following program terminate? If so, give the output. (a)
(b)
(c)
(d)
9. Can you always convert a while loop into a for loop? Convert the following while loop into a for loop. int i = 1; int sum = 0; while (sum < 10000) { sum = sum + i; i= i + 2; }