Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
95 views

Java Pseudocode Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

Java Pseudocode Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Java Pseudocode Questions

1) Given the pseudocode for performing Binary search in an array of elements sorted in
ascending order. What operation must be implemented in the 3rd so that the execution of binary
search is successful?
1. Middle element should be compared with x.
2. If x and the middle element match, we return the middle index.
3. _ _ _ _ _ _ _ _ _ _ _
4. Else (x is smaller than the middle element) recur for the left half
A. Else if x is greater than the middle element, then x can only lie in the right half subarray after
the middle element. So we recursively search for the right
B. Else if x is greater than the middle element, then x can only lie in the left half subarray after
the middle element. So we recursively search for left
C. None of the above
D. Else if x is less than the middle element, then x can only lie in the right half subarray after the
middle element. So we recursively search for the right

2) Predict the output of the given pseudo code if the value of the number is 6:
Read number
k=2
i=2
while i <= number:
k=k*i
i = i +1
end while
write k
A. 1440.0
B. 1340.0
C. 1700.0
D. 1560.0

3) What will happen for the below pseudocode:


Set Integer res = 0
do
--res
display res
res++
While(res >= 0)
End do-while
A. The program will not enter the loop.
Java Pseudocode Questions
B. Code will run infinite number of times.
C. Code will execute and the value of res will be displayed once.
D. Code will execute and the value of res will be displayed twice.

4) What is the output of the below pseudocode?


Set value = ' ' * 10;
print value
A. 100
B. 320
C. 10
D. 200

5) What happens when the below pseudocode is executed?


Set Integer value = 10
Set Integer salary= 0
While (value = 10)
salary = salary + 100
display salary
END While
A. Code executes successfully and the value of salary is displayed once.
B. Code executes successfully and nothing is displayed.
C. Code executes successfully the value of salary is displayed infinite times.
D. Compilation error.

6) Count the number of " * " printed by the given pseudo code when the input is 25.
Write "Please enter a number"
Read input
Repeat while input > 0
if( input > 0 and input <=12 )
Write *
else if ( input >12 and input <=24 )
Write **
else if ( input >24 and input< = 30 )
Write ***
input --
end if
End while
A. 39.0
B. 57.0
Java Pseudocode Questions
C. 35.0
D. 29.0

7) Count the number of " # " printed.


For m = 0 to 14 do
For n = 0 to 14 do
display '#'
End-for
if(m = 5) then do
break
End-if
End-for
A. 13
B. 84
C. 28
D. 63

8) Count the number of " # " printed.


For x = 0 to 8 do
For y = 0 to 6 do
display '#'
End-for
If(x = 2) then do
break
End-if
End-for
A) 14
B) 13
C) 20
D) 21

9) What will be the output of the following pseudocode?


Integer x, y, z
Set x = 4, y = 3, z = 1
if (x >> (z - 1) && y << (z + 1))
x=x+c
else
y = x << z
End if
Print x - y + z
A. 5
Java Pseudocode Questions
B. 3
C. 8
D. None of these

10) What will be the output of the given pseudo code if n = 10?
Read n
Initialize i to 5, sum to 0
while i < n do
increase sum by i
increment i
end while
Write sum
A. 35.0
B. 25.0
C. 45.0
D. 55.0

11) What will be the output of the following pseudocode?


Integer p, q
Set p = 1, q = 1
p = (p ^ 1) & (1) + (q ^ 1) & (1)
Print p + q
A. 2
B. 1
C. None of these
D. 0

12) Predict the output of the given pseudo code if the value of n is 35 :
Read n
i=0
While n % 10 != 0
n=n+3
i++
end while
n = n+i
print n
A. 55.0
B. 45.0
C. 50.0
Java Pseudocode Questions
D. 43.0

13) Predict the output of the following pseudocode


Integer x, y
Set x = 10, y = 8
Print ((x | 1) & (4) + (y ^ 1) & (1))
A. 1
B. 3
C. 2
D. 0

14) Predict the output of the given pseudo code if the value of n is 26 :
Read n
i=0
While n % 8 != 0
n=n+5
i++
end while
n=n+i
print n
A. 16
B. 32
C. 10
D. 62

15) What will be the output of the following pseudocode?


Set x = 'a' * 10;
print x
A. 97
B. 970
C. 10
D. 200

16) Predict the output of the given pseudocode


Set n = 14, sum = 0, i = 5
while i < n do
increase sum by 2 * i
increment i
end while
Java Pseudocode Questions
Write sum
A. 117
B. 130
C. 162
D. 140

17) Predict how many times the value of res will be displayed.
Set Integer res = 0
do
++res
display res
while(res <= 5)
End do-while
A. The program will not enter the loop.
B. Code will run infinite number of times.
C. Code will execute and the value of res will be displayed six times.
D. Code will execute and the value of res will be displayed five times.

18) What will be the output of the below pseudocode?


Set Integer x = 0
do
++x
display x
x--
while(x >= -1)
End do-while
A. The program will not enter the loop.
B. The code will run an infinite number of times.
C. Code will execute and the value of res will be displayed once.
D. Code will execute and the value of res will be displayed twice.

19) Predict the output of the below pseudocode


Integer p, q
Set p = 11, q = 20
p = (p & 1) & (5) + (q ^ 1) & (5)
Print p + q
A. 3
B. 6
C. 2
Java Pseudocode Questions
D. 5

20) Predict the output of the following pseudocode


Integer p, q
Set p = 11, q = 20
p=q-p
Print p
A. 9
B. 3
C. 6
D. 2

21) What will be the output of the following pseudocode for p = 3 and q = 4?
int fun1(int p, int q)
if(q EQUALS 0)
return 0
if(q mod 2 EQUALS 0)
return fun1(p + p, q/2) .
return fun1(p + p, q/2) + p
End function fun1()
A. None of the options
B. 7
C. 12
D. 8

22) What will be the output of the following pseudocode?


Integer x, y, Z, a
Set x=2,y=1,z=5
a = (x AND y) OR (z + 1)
Print a
A. 5
B. 3
C. 2
D. 1

23) What will be the output of the following pseudocode for a = 2, b = 3?


doSomething(Integer a, Integer b)
if(b EQUALS 1)
return 0
Java Pseudocode Questions
else
return a+ doSomething(a, b-1)
End function doSomething()
A. 3
B. 4
C. 2
D. 1

24) What will be the output of the following pseudocode?


Integer a, n, sum, q, r
Set a=123, n=0, sum=0
Set q=a
while (q mod 10 NOT EQUALS 0)
n=n+1
q=q/10
End while
Print n
while (a greater than 0)
r=a mod 10
sum =sum + r
a =a/power(10, n- 1)
End while
Print sum
A. 3 2
B. 6 4
C. 6 5
D. 3 4

25) What will be the output for the following pseudocode?


Integer a=5,b=8,c
if(a>8 OR b < 7)
c=a+b
elseif(a + b > 9)
c=a-b
else
a=a+5
c=c-2
end if
a=a+b
Java Pseudocode Questions
Print a and c
b=b-5
A. None of the mentioned
B. 5-3
C. 5 1
D. 13-3

26. What will happen when following pseudocode is executed?

A. Code executes successfully and value of salary is displayed once.


B. Code executes successfully and nothing is displayed.
C. Code executes successfully and value of salary is displayed infinite number of times.
D. Compile time error.

27) What will happen when following program is executed?

A. Code will run infinite number of times.


B. The program will not enter the loop.
C. Code will execute and value of res will be displayed twice.
D. Code will execute and value of res will be displayed once.

28) How many times will ‘#’ be displayed?

A) 15
B) 1
C) 2
D) 8

29) What will be the output of the following pseudocode?


Java Pseudocode Questions

A. 0
B. 3
C. 1
D. 2

30) What will be the output of the following pseudocode?

A. SevenTwoHello
B. OneHello
C. SevenTwo
D. Seven

31) What will be the output of the following pseudocode?


Integer a, b, c
Set a = 4, b = 3, c = 1
if (a >> (c-1) && b << (c+1))
a=a+c
Else
b = a << c
End if
Print a - b + c
print n
A. 3
B. 5
C. 8
D. None of these

32) What will be the output of the following pseudocode?


Integer a, p
Set a = 5
a=a+1
a=a*2
a=a/2
Java Pseudocode Questions
a=a/5+6
print p
A. 0
B. 1
C. 2
D. 7

33) What will be the output of the following pseudocode?


Integer a, b, c
Set b = 8, a = 2
c=a^b
if ((c ^ b))
b=0
End if
print b
A. 3
B. 0
C. 10
D. 2

34) What will be the output of the following pseudocode?


Integer a, b, c
Set b = 40, a = 20 c = 20
a=a+c
c=c+a
a=a+c
c=c+a
print a + b + c
A. 40
B. 100
C. 300
D. None of these

35) What will be the output of the following pseudocode?


Integer a, b,
Set a = 1, b = 1
a = (a ^ 1) & (1) + (b ^ 1) & (1)
print a + b
A. 1
Java Pseudocode Questions
B. 2
C. 0
D. None of these

36) What is the output of this C code?


#include <stdio.h>
int main()
{
int i= 0, j = 0;
while (I1: i < 2)
{
i++;
while (j < 3)
{
printf("loop\n");
goto I1;
}
}
}
A. loop loop loop loop
B. loop loop
C. Compile time error
D. Infinite loop

37) What is the output of this code?


#include <stdio.h>
int main()
{
static int i= 5;
if (--i){
printf("%d",i);
main();
}
}
A. 4 3 2 1
B. 4 4 4 4
C. 0 0 0 0
D. 1 2 3 4
38) Consider the below given fragment of code.
Java Pseudocode Questions
int f(int &x, int c) {
c = c - 1;
if (c == 0) retum 1;
x = x + 1;
return f(x, c) * x;
}
In above program the first parameter is passed by reference and the second parameter is
passed by value. If the value of p = 5 before the call then what is the value that returned by f(p,
p)?
A. 6561
B. 161051
C. 55440
D. 3024

39) Comment on the output of this C code?


#include <stdio.h>
int main()
{
int x = 3,i=0;
do{
X= x ++;
i++;
} while (i != 3);
printf(“%d\n", x);
}
A. Output will be 5
B. Output will be 6
C. Output will be 3
D. Undefined behavior

40) What will be the value of s if n=127?


Read n
i=0,s=0
Function Sample(int n)
while(n>0)
r=n%l0
p=8^i
s=s+p*r
i++
Java Pseudocode Questions
n=n/10
End While
Return s;
End Function
A. 27
B. 187
C. 84
D. 120

41) What will be the output if limit = 6?


Read limit n1 = 0, n2= 1, n3=1, count = 1;
while count <= limit
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
End While
A. 1235813
B. 12358
C. 123581321
D. 12358132

42) What will be the value of even_counter if number = 2630?


Read number
Function divisible(number)
even_counter = 0, num_remainder = number;
while (num_remainder)
digit = num_remainder % 10;
if digit != 0 AND number % digit == 0
even_counter= even_counter+1
End If
num_remainder= num_remainder / 10;
End While
return even_counter;
A. 3
B. 4
C. 2
D. 1
Java Pseudocode Questions

43) What will be the value of t if a = 56 , b = 876?


Read a,b
Function mul(a, b)
t=0
while (b != 0)
t=t+a
b=b-1
End While
return t;
End Function
A. 490563
B. 49056
C. 490561
D. None of the mentioned

44) Code to sort given array in ascending order:


Read size
Read a[1],a[2],…a[size]
i=0
While(i<size)
j=i+1
While(j<size)
If a[i] < a[j] then
t= a[i];
a[i] = a[j];
a[j] = t;
End If
j=j+1
End While
i=i+1
End While
i=0
While (i<size)
print a[i]
i=i+1
End While
wrong statement?
A. Line 4
Java Pseudocode Questions
B. Line 6
C. Line 7
D. No Error

45) Consider the following piece of code. What will be the space required for this code?
int sum(int A[], int n)
{
int sum = 0, i;
for(i = 0; i < n; i++)
sum = sum + A[i];
return sum;
} // sizeof(int) = 2 bytes
A. 2n + 8
B. 2n + 4
C. 2n + 2
D. 2n

46) What will be the output of the following pseudo code?


For input a=8 & b=9.
Function(input a,input b)
If(a<b)
return function(b,a)
elseif(b!=0)
return (a+function(a,b-1))
else
return 0
A. 56
B. 88
C. 72
D. 65

47) What will be the output of the following pseudo code?


Input m=9,n=6
m=m+1
N=n-1
m=m+n
if (m>n)
print m
else
Java Pseudocode Questions
print n
A. 6
B. 5
C. 10
D. 15

49) What will be the output if limit = 6?


Read limit n1 = 0, n2= 1, n3=1, count = 1;
while count <= limit
count=count+1
print n3
n3 = n1 + n2
n1 = n2
n2 = n3
End While
A. 1235813
B. 12358
C. 23581321
D. 12358132

50) What will be the output of the following pseudocode for a = 9, b = 7?


Integer funn(Integer a, Integer b)
Integer c
Set c = 2
b = b mod c
a = a mod c
return a + b
End function funn()
A. 2
B. 5
C. -5
D. 17

You might also like