404 Not Found
Directions to Solve In questions below, each passage consist of six sentences. The first and sixth sentence are given in the begining. The middle four sentences in each have been removed and jumbled up. These are labelled as P, Q, R and S. Find out the proper order for the four sentences.
|
S1: | We now know that the oceans are very deep. |
P : | For example, the Indian ocean has a range called the Indian Ridge. |
Q : | Much of it is fairly flat. |
R : | However, there are great mountain ranges as well. |
S : | On average the bottom is 2.5 miles to 3.5 miles down |
S6: | This reaches from the India to the Antarctic. |
ANS:A - SQPR
No answer description is available.
Q2: What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i=0;
i++;
if(i<=5)
{
printf("AptitudeCrack");
exit(1);
main();
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i=0;
i++;
if(i<=5)
{
printf("AptitudeCrack");
exit(1);
main();
}
return 0;
}
ANS:D - Prints "AptitudeCrack"
Step 1: int i=0; The variable i is declared as in integer type and initialized to '0'(zero). Step 2: i++; Here variable i is increemented by 1. Hence i becomes '1'(one). Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied and it enter into if block statements. Step 4: printf("AptitudeCrack"); It prints "AptitudeCrack". Step 5: exit(1); This exit statement terminates the program execution. Hence the output is "AptitudeCrack".
Q3: What will be the output of the program?
int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);
int I = 0;
outer:
while (true)
{
I++;
inner:
for (int j = 0; j < 10; j++)
{
I += j;
if (j == 3)
continue inner;
break outer;
}
continue outer;
}
System.out.println(I);
ANS:A - 1
The program flows as follows: I will be incremented after the while loop is entered, then I will be incremented (by zero) when the for loop is entered. The if statement evaluates to false, and the continue statement is never reached. The break statement tells the JVM to break out of the outer loop, at which point I is printed and the fragment is done.
Q4: What will be the output of the program?
for (int i = 0; i < 4; i += 2)
{
System.out.print(i + ' ');
}
System.out.println(i); /* Line 5 */
for (int i = 0; i < 4; i += 2)
{
System.out.print(i + ' ');
}
System.out.println(i); /* Line 5 */
ANS:A - 0 2 4
Compilation fails on the line 5 - System.out.println(i); as the variable i has only been declared within the for loop. It is not a recognised variable outside the code block of loop.
Q5: What will be the output of the program?
int x = 3;
int y = 1;
if (x = y) /* Line 3 */
{
System.out.println('x =' + x);
}
int x = 3;
int y = 1;
if (x = y) /* Line 3 */
{
System.out.println('x =' + x);
}
ANS:A - x = 1
Line 3 uses an assignment as opposed to comparison. Because of this, the if statement receives an integer value instead of a boolean. And so the compilation fails.
Q6: What will be the output of the program?
Float f = new Float('12');
switch (f)
{
case 12: System.out.println('Twelve');
case 0: System.out.println('Zero');
default: System.out.println('Default');
}
Float f = new Float('12');
switch (f)
{
case 12: System.out.println('Twelve');
case 0: System.out.println('Zero');
default: System.out.println('Default');
}
ANS:A - Zero
The switch statement can only be supported by integers or variables more 'narrow' than an integer i.e. byte, char, short. Here a Float wrapper object is used and so the compilation fails.
Q7: What will be the output of the program?
int i = 0;
while(1)
{
if(i == 4)
{
break;
}
++i;
}
System.out.println('i = ' + i);
int i = 0;
while(1)
{
if(i == 4)
{
break;
}
++i;
}
System.out.println('i = ' + i);
ANS:A - i = 0
Compilation fails because the argument of the while loop, the condition, must be of primitive type boolean. In Java, 1 does not represent the true state of a boolean, rather it is seen as an integer.
Q8: What will be the output of the program?
public class Delta
{
static boolean foo(char c)
{
System.out.print(c);
return true;
}
public static void main( String[] argv )
{
int i = 0;
for (foo('A'); foo('B') && (i < 2); foo('C'))
{
i++;
foo('D');
}
}
}
public class Delta
{
static boolean foo(char c)
{
System.out.print(c);
return true;
}
public static void main( String[] argv )
{
int i = 0;
for (foo('A'); foo('B') && (i < 2); foo('C'))
{
i++;
foo('D');
}
}
}
ANS:A - ABDCBDCB
'A' is only printed once at the very start as it is in the initialisation section of the for loop. The loop will only initialise that once. 'B' is printed as it is part of the test carried out in order to run the loop. 'D' is printed as it is in the loop. 'C' is printed as it is in the increment section of the loop and will 'increment' only at the end of each loop. Here ends the first loop. Again 'B' is printed as part of the loop test. 'D' is printed as it is in the loop. 'C' is printed as it 'increments' at the end of each loop. Again 'B' is printed as part of the loop test. At this point the test fails because the other part of the test (i < 2) is no longer true. i has been increased in value by 1 for each loop with the line: i++; This results in a printout of ABDCBDCB
public class Delta
{
static boolean foo(char c)
{
System.out.print(c);
return true;
}
public static void main( String[] argv )
{
int i = 0;
for (foo('A'); foo('B') && (i < 2); foo('C'))
{
i++;
foo('D');
}
}
}
Q9: What will be the output of the program?
for(int i = 0; i < 3; i++)
{
switch(i)
{
case 0: break;
case 1: System.out.print('one ');
case 2: System.out.print('two ');
case 3: System.out.print('three ');
}
}
System.out.println('done');
for(int i = 0; i < 3; i++)
{
switch(i)
{
case 0: break;
case 1: System.out.print('one ');
case 2: System.out.print('two ');
case 3: System.out.print('three ');
}
}
System.out.println('done');
ANS:A - done
The variable i will have the values 0, 1 and 2. When i is 0, nothing will be printed because of the break in case 0. When i is 1, 'one two three' will be output because case 1, case 2 and case 3 will be executed (they don't have break statements). When i is 2, 'two three' will be output because case 2 and case 3 will be executed (again no break statements). Finally, when the for loop finishes 'done' will be output.
Q10: What will be the output of the program?
public class Test
{
public static void main(String args[])
{
int i = 1, j = 0;
switch(i)
{
case 2: j += 6;
case 4: j += 1;
default: j += 2;
case 0: j += 4;
}
System.out.println("j = " + j);
}
}
public class Test
{
public static void main(String args[])
{
int i = 1, j = 0;
switch(i)
{
case 2: j += 6;
case 4: j += 1;
default: j += 2;
case 0: j += 4;
}
System.out.println("j = " + j);
}
}
ANS:D - j = 6
Because there are no break statements, the program gets to the default case and adds 2 to j, then goes to case 0 and adds 4 to the new j. The result is j = 6.