Find the output of the following code (Java for ICSE)

MokshyaPriyadarsheeB 7,418 views 4 slides May 05, 2020
Slide 1
Slide 1 of 4
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4

About This Presentation

This document consists of some important practice questions for ICSE Class X Exams from the section of find the output. It is also supplemented with past years question papers


Slide Content

Find OUTPUT of The following Code
1 int i,k;
for(i=1,k=1;i<=5;k+=i,i++)
System.out.println(i+" "+k);
2 int x=5,y;
y=++x;
System.out.println(y);
3 int a = 25;
System.out.println(a++);
System.out.println(--a);
4 int x = 5, y=6, z;
z = x++ + ++y;
System.out.println(z);
5 int m=12;
int n = m++ * 5 + --m
System.out.println(n);
6 int y=14;
int z = (++y * (y++ + 5))
7 int x = 20, y = 5, z;
z = x > y ? 100 : 50;
System.out.println(z);
8 int x =25, y;
y = ++x % 6;
System.out.println(y);
9 int a = 10, b = 5, p;
p = a++ + ++b;
System.out.println(p+” “+a+” “+b);
10 for(int x = 1; x<=15; x+=2)
System.out.println(x);
11 int x = 5;
while(x>10)
{
System.out.println(x);
x++;
}
12 int a = 5;
do
{
System.out.println(a);
a++;
}while(a<4);
13 int k=5,j=9;
k+= k++ - ++j + k;
System.out.println(“k=”+k);
System.out.println(“j=”+j);
14 double b = -15.6;
double a = Math.rint(Math.abs(b));
System.out.println(“a=”+a);
15 State the number of times loop will be
executed and the final output :
int p = 200;
While(true)
{



if(p<100)
break;
p=p-20;
}
System.out.println(p);
16 int x = 1, y = 5;
while (x<y)
{
y++;
x+=2;
}
System.out.println(x+” “+y);




17 for(int x = 1; x<=20; x++)
{
if(x % 5 == 0)
continue;
System.out.println(x);
}
18 for(int x = 1; x<=20; x++)
{
if(x % 7 == 0)
break;
System.out.println(x);
}
19 int a = 25, b = 39;
while(b>0)
{
b = b – a;
a = a – b;
}
System.out.println(a + “ “+b);
20 for(int x=0;x<=15;x+=2);
System.out.println(x);
21 int a = 5, b = 7, c;
c = ++a + b++ + --a;
System.out.println(c);
22 int x = 20, y = 25;
x = ++x + y++ + --y + --x;
System.out.println(x);
23 int n = 2,m;
m = --n *2*n;
System.out.println(m);
24 int a = 25;
int b = (++a * 4) % 25;
System.out.println(b);
25 char c = ‘A’;
short m = 26;
int n = c + m;
System.out.println(n);
26 What will be the value of following expression
if the value of m = 5 and n=20?
(m + n) > 25 ? 200 : 20;

27 Int x = 99, y = 10;
y = ++x;
System.out.println(“X:”+x+” Y:”+y);
28 double x = 0.055,y = 100.05;
System.out.println((int)(x*y));
29 int x = 10, y=15;
x = x+y;
y = x-y;
x = x-y;
System.out.println(x+ “ *** ”+y);
30 int sum = 20;
if(sum<20)
System.out.print(“Under ”);
else
System.out.println(“Over “);
System.out.println(“the limit”);
31 What will be the output, if n = 1 and if n= 2 in
the following code?
switch(n)
{
case 1:
System.out.println(“One);
break;
case 2:
System.out.println(“ Zero”);
default:
System.out.println(“Wrong input”);
}
32 int s=1,p=0;
for(int j = 1;j<=8;j++)
{
if(j<=4)
s*=j;
else
p+=j;
}
System.out.println(s+” “+p);
33 If array[]={1,9,8,5,2};
i) What is array.length?
ii) What is array[2]?
34 int x[]={1,2,3,4,5}, y ={5,4,3,2,1};
int i,j;
for(i=0,j=x.length;i<x.length;i++,j- -)
System.out.println(x[i] * y[j]);
35 String s = “Please come, let us go to play”;
System.out.println (s.substring(7,11));
System.out.println (s.lastIndexOf(‘o’));
System.out.println (s.toUpperCase());
System.out.println (s.charAt(17));
System.out.println (s.indexOf(9,’o’));
System.out.println (s.substring(0,6) +
s.substring(20,22));
36 Sting k=”WELCOME TOPPERS”
System.out.println(k.toLowerCase());
System.out.println(k.length());
System.out.println(k.indexOf(‘E’));
System.out.println(k.replace(‘O’,’A’));
System.out.println(k.substring(8));
37 String n = “Computer Knowledge.”;
String m = “Computer Application”;
System.out.println
(n.substring(0,8).concat (m.substring(9)));
System.out.println(n.endsWith(“e”);
38 System.out.println(“Four:”+(4+2));
System.out.println(“Four:”+2+2);
39 State the output of the following code
fragment, where int choice =1, x= 0;
y = 0, z=0;
switch(choice++)
{
case 2: x++; y--; z++;
break;
case 3: x+=2; y+=3; z-=3;
default: ++x; ++y; ++z;
}
System.out.println(“X=”+x+”Y =”+y+”Z=”+z);
Questions to practice to find LOGICAL and SYNTAX error in the code
1. public int getData(int num1, int num2)
{
int result = num1 + num2;
System.out.println(“Result is :” +
result);
}
2. class Add
{
public void doAddition(int x, y)
{
System.out.print(x+y);
}
}
3. if(x = 1)
k=100;
else
k = 10;
4. if ( x > y)
System.out. println(“y is greater”);
else
System.out. println(“x is greater”);
5. int i=5, j = 10
if ( (i < j) || (i=10))
System.out.println(“OK”);
System.out.println(“not OK);
6. int x=0;
while(x < 10)
System.out.println(x);
x ++;
7. for ( x = 0; x>= 10; x- -)
System.out.println(x);
8. for (i = 0, i <= 25; i ++)
System.out.println(i);
System.out.println(“the value is “;x);

9. public int add(int x,int y)
{
int z=x + y;
}
10. int a = 5 , b = 7 , c = 1;
if (a > b || b > c)
System.out.println(a + “ is greater”);
11. int a =90, b = 45, c = 45
if(a = = 90 && b = = 90 && c = = 90)
System.out.println(“Right angle
Triangle”);
12. double p =1000.00, t = 5.0, r = 10.5;
I = p * r * t / 100;
System.out.println(I);
13. double average = M1+M2+M3+M4 / 4;
14. String s = ‘computer’;
15. int l = “Good Morning”.length;
16. for (int x = 1; x < = 10 ; x++)
{
n = 1;
System.out.println(n);
n++;
}
correct the code to get 1 3 5 7 9 11 13
15 17 19 output.
17. int x, y, z;
x = 6;
y = 7;
x + y = z;
System.out.println(z);
18. int a[] = new int [10];
for( x =1 ; x<=15 ; x++)
a[x] = x * x;
19. int n = integer.ParseInt(br.readline());
20. String st = “School”;
System.out.println(st.reverse( ));
21. int x = 5, y = 8, temp;
temp = x;
x = y;
y = temp;
System.out.println(x, y, temp);
22. int x[ ] = [3,6,8,4,7,0,4,1,5];
23. int ar[ ] = [3,6,8,4,7,0,4,1,5];
System.out.println(ar.length());

Express the following in Java expression

(1-y
3
)
0.5
√ (x2 – x1)
2
+ (y2 - y1)
2






–b + (b
2
-4ac)/2a

3x
2
+2y [2011]
x - y

(x
2
- 2y
2
)
3



(1 + x
4
)
0 .25


a = (0.05 – 2y
3
)/x - y

A
3
+ B
3
+ C
3
– 3ABC


x
1 /3





√ l
2
+ b
2


x – [ y – {+ (a + b – c – d)}]

3x
2
y+2yx
2

( x – y)
0 .5


s = ut + ½at
2

(a + b)
n

√3 + b

√ 2as + u
2
(2012)
5
x
* 7 – 5
x

5
x+2
– 5
x+1

2AB + 2BC + 2CA
X
2
Y
2
+ Y
2
Z
2
+ Z
2
+ X
2