JAVA OUTPUT QUESTION FOR PRACTISE (ARRAYS)
JAVA OUTPUT QUESTION FOR PRACTISE (ARRAYS)
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?
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;
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);
}
}
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);
}
}