[go: up one dir, main page]

0% found this document useful (0 votes)
117 views18 pages

JAVA OUTPUT QUESTION FOR PRACTISE (ARRAYS)

Uploaded by

amar.khera1504
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)
117 views18 pages

JAVA OUTPUT QUESTION FOR PRACTISE (ARRAYS)

Uploaded by

amar.khera1504
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/ 18

Output Related Questions (Looping)

1. What will be the output for the following program?


public class Test
{
public static void main(String[] args)
{
int i = 0;
for ( String s="a"; s.compareTo("aaa") ! =0 ; s =
s + "a" )
System.out.print(s);
}
}

What will be the output for the following program?


2. public class Test
{
public static void main(String[] args)
{
for (int i = 0; i < 1; System.out.println("HI"))
System.out.print("HELLO");
}
}

3. What will be the output for the following program?


public class Test
{
public static void main(String[] args)
{
int j=0;
for (int i = 0; i < 1; j++)
System.out.println("HELLO");
}
}

4. What will be the output for the following program?


public class Test
{
public static void main(String[] args)
{
for ( int i = 0; true & ++i<2; i++)
System.out.print(i);
}
}

5. What will be the output for the following program?


public class Test
{
public static void main(String[] args)
{
boolean b=false;
for ( int i = 0; b | ++i<2; i++)
{
System.out.print(i);
b=!b;
}
}
}

6. public class Test


{
public static void main (String [] args)
{
for (int i = 0, double x=3.0 ; i < 2 ; i++)
System.out.println("HELLO ");
}
}

7. public class demo


{
public static void main(String[] args)
{
int i=0;
for( ; ; )
{
if(i>5)
break;
else
i=i+2;
System.out.println(i);
}
}
}

8. public class demo


{
public static void main(String[] args)
{
int a,b;
for(a=6,b=4;a<=24;a=a+6)
{
if(a % b==0)
break;

System.out.println(a);
}
}
}
9. class Demo
{
public static void main(String s[])
{
int a, b;
for(a = 1, b = 4; a < b; a++, b--)
{
System.out.println("a = " + a);
System.out.println("b = " + b);
}
}
}
10. public class Test1
{
public static void main(String[] args)
{
int i=0;
for(i=100; i<=0; i=i-10)
{
System.out.print(i+",");
}

}
11. public class Test {
public static void main(String[] args)
{
int i = 0;
for (System.out.println("HI") ; i < 1 ; i+
+ )
System.out.println("HELLO GEEKS");
}
}
12 public class Test
{
public static void main(String[] args)
{
for(int i = 0; i<5; i++)
{
System.out.println("Hello");
break;
}
}
}
13 public class Test
{
public static void main(String[] args)
{
String s = "friends";
int x = 0;

do
{
System.out.print(s.charAt(x));
x++;
} while (x < 2);
}
}
14. public class Test
{
public static void main(String[] args)
{
while(true)
{
System.out.println("cppbuzz");
}
}
}
15. public class Test
{
public static void main(String[] args)
{
int i;
for ( i = 5 ; i > 10; i ++ )
System.out.println( i
);
System.out.println( i * 4 );
}
}
16. public class Test
{
public static void main(String[] args)
{
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < i; j++)
{
System.out.print(i + " " + j
+ ",");
}
}
}
}
17. public class Test
{
public static void main(String[] args)
{
int i, s = 0;
for (int k = 0; k < 5; k++)
{
i = 0;
do
{
i++; s++;
}while (i < k);
}
System.out.println(s);
}
}
18. public class Application
{
public static void main(String[] args)
{
String one = "Hello";
String two = "Hello";
if(one == two)
{
System.out.println("one ==
two");
}
else
{
System.out.println("one != two");
}
}
}
19. public class TestWhile
{
public static void main(String[] args)
{
int i = 1;
int j = 20;
int k = 31;
while (i < j)
{
k += (i * j);
i = i * 2;
j--;
}
System.out.println("i = " + i + " j = "
+ j + " k = " + k);
}
}
20. class WhileExample
{
public static void main(String s[])
{
int n = 5;
while( n > 0 )
{
n--;
System.out.println("n = " +
n );
}
}
}
21. How many times 'ITER' will be printed?
public class C1
{
public static void main(String[] args)
{
for(int i = 0; i<5; i++)
{
System.out.println("ITER");
i++;
}
}
}
22. public class C2
{
public static void main(String[] args)
{
for(int i = 0; i<5; )
{
System.out.println("Hello");
}
}
}
23. class C3
{
public static void main (String args[])
{
for(int i=0; 0; i++)
{
System.out.println("ICP");
}
}
}
24. public class Test
{
public static void main(String[] args)
{
int i;
for (int i = 0; i < 3; i++);

System.out.println(i)
}
}
25. public class C5
{
public static void main(String[] args)
{
while(true)
{
System.out.println("ITER"
);
break;
}
}
}
26. public class Output1
{
public static void main(String[] args)
{
for (int i = 0; i < 10; i++)
int x = 10;
System.out.println("x");

}
}
27. public class Output2
{
public static void main(String[] args)
{
int i = 0;
for (System.out.println("ITER"); i <
1; i++)
System.out.println("SOA");
}

}
28. public class Output3
{
public static void main(String[] args)
{
for (int i = 0 ; ; i++)
System.out.println("ICP");
}

}
29. public class Output4
{
public static void main(String[] args)
{
for (int i = 0 ; i < 1 ;
System.out.print("ITER ") )
System.out.println("SOA");
}
}
30. public class Output5
{
public static void main(String[] args)
{
int i = 1, j = 1;
for ( ; ; )
{
if (i > 5)
break;
else
j += I ;
System.out.println(j);
i += j;
}
}

}
31. public class Output5
{
public static void main(String[] args)
{
int i = 0;
while(true)
{
System.out.println(++i);
break;
}
}
}
32. public class Output5
{
public static void main(String[] args)
{
int i = 3, j=5;
do
{
System.out.print(i*j);
} while(++i < --j);
}
}
33. public class Output5
{
public static void main(String[] args)
{
char a = 'a';
while(++a<=100)
{

System.out.print(a);
}
}
}
34. public class Output5
{
public static void main(String[] args)
{
for(int i=0; false; i++)
System.out.println("Hello");
}
}
35. Find output of the following pseudocode?

Step 1: Initialize count to 1;


Step 2: While count is less than 10
Step 2.1: Print count;
Step 2.2: count = count + 3;
Step 3: Stop.
36. public class Alpha
{
public static void main(String [] args)
{
int cnt=0;
while(true)
{
if(cnt > 4)
break;
if(cnt==0)
{
cnt++;
continue;
}
System.out.print(cnt + ",");
cnt++;
}
}
}
37. public class Alpha
{
public static void main(String [] args)
{
while(i<3)
{
do
{
System.out.print(j + ",");
j++;
}while(j<4);
i++;
}
}
}
38. class Test
{
public static void main(String[] args)
{
int i = 0;
for (System.out.println("HI"); i < 1; i+
+)
System.out.println("HELLO ITER");
}
}
39. public class Alpha
{
public static void main(String [] args)
{
int i , j;
for(i=0;i<3;i++)
{
for(j=1;j<4;j++)
{
i%=j;
System.out.println(j);
}
}
}
}
40. public class Test
{
public static void main(String agrs[])
{
int i;
for(i=1; i<=10; i++);
System.out.print(i);
}
}
41. What will be the output for the following program?

class Test
{
public static void main(String[] args)
{
do
{
while (true)
System.out.printl
n("HELLO");
}while (false);
}
}
42. What will be the output for the following program?
class Test
{
public static void main(String[] args)
{
do
System.out.println("FRIENDS");
while (true);
System.out.println("ENEMY");
}
}
43. What will be the output for the following program?

class Test
{
public static void main(String[] args)
{
int x = 1, y = 2;
do
{
System.out.println("FRIENDS");
} while (x < y);
System.out.println("ENEMY");
}
}
44. public class Test
{
public static void main(String agrs[])
{
for(int i=1; i<=10; i++);
System.out.print(i);
}
}
45. class Test
{
public static void main(String[] args)
{
for(int i = 0; 1; i++)
{
System.out.println("Hello");
break;
}
}
}
46. class Test
{
public static void main(String[] args)
{
do
{
System.out.print(1);
do
{
System.out.print(2);
} while (false);
} while (false);
}
}
47. public class Testing
{
public static void main(String[] args)
{
loop1:
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (i == 3)
break loop1;

System.out.println("i = " + i + " j = " + j);


}
}
}
}
48. public class Testing
{
public static void main(String[] args)
{

int x = 3, k;
while (x-- >= 0)
{
System.out.println
(x);
}

}
}
49. public class Testing
{
public static void main(String[] args)
{
int x = -10;
while (x++ != 0)
;
System.out.println(x);
}
}
50. Find the output of the code:
public class Demo
{
public static void main (String []args)
{
int n = 6, i=0;
for (i=0; Math.pow(2,i)<=n; i++);
System.out.println(i);
}
}
51. Find the output of the code:
public class Demo
{
public static void main (String []args)
{
int n = 6, i=0;
while (Math.pow(2,i)<=n);

System.out.println(i);
}
}
52. Find the output of the code:
public class Demo
{
public static void main (String
[]args)
{
int n = 6,i,j;
for (i=0,j=0; i<n; i++,j++)

System.out.println(i+" "+j);
}
}
53. Find the output of the code:
public class Demo
{
public static void main (String []args)
{
do
{
System.out.println(i);
} while (i < = 5 );
}
}
54. class Test
{
public static void main(String[] args)
{
do
{
while (true)
System.out.println("HELLO");
}while (false);
}
}
55.
class Test
{
public static void main(String[] args)
{
do
{
System.out.print(1);
do
{
System.out.print(2);

} while (false);

} while (false);
}
}

56. Public class Test


{
public static void main(String[] args)
{
int x = 30, y = 50;
if (x < y)
int a = 40;
else
{
System.out.println("BYE");
}
}
}
57. Public class Test
{
public static void main(String[] args)
{
for(i=0;i<10;i++)
{
for (j=-5;j<10;j++)
{
if(i==j )
break;
System.out.println(“Hello”);
}
}
}
}
58. Public class Test
{
public static void main(String[] args)
{
int i=2;
for( ; ; )
{
System.out.println("Hi");
}
}
}
59. Public class Test
{
public static void main(String[] args)
{
for(int i = 0; i<5; i++)
{
System.out.println("Hello");
i++;
i--;
}
}
}
60. Public class Test
{
public static void main(String[] args)
{
for(int i = 0; i<5; i=5 )
{
System.out.println("Hello");
}
}
}
61. Public class Test
{
public static void main(String[] args)
{
String s = "School";
int x = 0;
do
{
System.out.print(s.charAt(x));
x++ ;
} while (x < 2)
}
}
62. public class Alpha
{
public static void main(String [] args)
{
int i=0;
for(i=1; i<=6;i++)
{
if(i%3==0)
continue;

System.out.print(i+",");
}
}
}
63. Find the output of the code:
public class Demo
{
public static void main (String []args)
{
int n = 6;
do
{
System.out.println
(Math.abs (-n));
} while (n != 0);
}
}

You might also like