COMPUTER PROGRAMMING

ICSE Important Short Type Question:

RAMAKRISHNA ACADEMY 

Sl No.

Questions

1.       

What are the types of casting shown by the following example:

i) char c=(char) 120;

ii) int x = ‘y’;

2.       

Write down the java expression for the Following

3.       

Rewrite the following using ternary operator:

if(x%2==0)

     System.out.print(“EVEN”);

else

     System.out.print(“ODD”);

4.       

Give the output of the following expression when a=7:

a+=a++ + ++a + - -a + a- -;

5.       

Rewrite the following program segment using the if..else statement.

comm=(sales>15000)? sales*5/100 : 0 ;

6.       

What will be the result stored in x after evaluating the following expression?

int x= 4;

x+= (x++) + (++x) + x;

7.       

What are the values of x and y when the following statement are executed?

int a=63, b=36;

boolean x=(a<b)? true:false;

int y=(a>b)? a: b;

8.       

State the values of n and ch :

1.      char c= ‘A’;

2.      int n= c + 1;

3.      char ch=(char)n;

9.       

What will be the output of the following Code?

i)   int k=5,j=9;

     k+=k++ - ++j + k;

     System.out.println(“k = ”+k);

     System.out.println(“j = ”+j);

ii) double b = -15.6;

    double a = Math.rint(Math.abs(b));

    System.out.println(“a = ”+a);

10.   

What is the result stored in x, after evaluating the following expression:

int x=5;

x= x++ * 2 + 3 * - x;

11.   

The following is a segment of a program

x=1; y=1;

if(n>0)

{

   x=x+1;

   y=y-1;

}

What will be the value of x and y, if n assumes a value i) 1 ii) 0 ?

12.   

Rewrite the following  using Ternary operator :

If(income<=10000)

tax=0;

else

tax=12;

13.   

Write equivalent Java expressions for the following:

14.   

Give the output of the following:

a) Math.floor (-4.7)

b) Math.ceil(3.4) + Math.pow(2, 3)

c) Math.floor(-126.349)

d) Math.max(45.6,17.3)

e) Math.min(-0.0,0.0)

f) Math.pow(4,3)

g) Math.sqrt(625)

h) Math.cbrt(125)

i) Math.max(11,11)

j) Math.ceil(-12.56)

k) Math.floor(15.36)

l) Math.round(146.5)

m) Math.max(-17, -19)

n) Math.ceil(7.8)

o) Math.ceil(4.2)

p) Math.abs(-4)

15.   

Evaluate the following expression if the value of the variable are a=2, b=3 and c=9.

i)   a – (b++) *(- -c);

ii)  a* (++b) % c;

16.   

If a=5, b=9 calculate the value of a a+= a++ - ++b +a

17.   

Write a statement in Java for 


18.   

What is the value of m after evaluating the following expression:

m-=9 % ++n + ++n/2; when int m=10, n=6

19.   

Predict output of the following

i)   Math.pow(25,0.5) + Math.ceil(4.2);

ii)  Math.round(14.7) + Math.floor(7.9);

20.   

Write the output of the following:

System.out.println(“Incredible”+“\n”+“world”);

21.   

Convert the following segment into an equivalent do loop.

int x,c;

for (x=10, c=20; c>=10; c = c – 2)

x++;

22.   

Give the output of the following program segment and also mention how many times the loop is executed:

int i;

for (i = 5 : i > 10; i ++)

System.out.println(i);

System.out.println(i * 4);

23.   

Convert the following while loop to the corresponding for loop:

int m = 5, n = 10;

while (n>=1)

{

      System.out.println(m*n);

      n–;

}

24.   

Convert following do-while loop into for loop.

int i = 1;

int d=5;

do

{

     d=d*2;

     System.out.println(d);

     i++ ;

} while (i<=5);

25.   

What will be the output of the following code?

int m=2;

int n=15;

for(int i = 1; i<5;i++)

   m++; --n;

System.out.println(“m =”+m);

System.out.println(“n =”+n);

26.   

Analyze the given program segment and answer the following questions:

for(int i=3;i<=4;++)

{

      for(int j=2;j<i;j++)

      {

                System.out.print(“ ”);

      }

System.out.println(“WIN”);

}

i.                    How many times does the inner loop execute ?

ii.                  Write the output of the program segment.

27.   

Analyse the following program segment and determine how many times the loop will be executed and what will be the output of the program segment.

int k=1, i=2;

while (++i<6)

   k*=i;

System.out.println(k);

28.   

How many times will the following loop execute? What value will be returned?

int x = 2, y = 50;

do

{

   ++x;

   y- = x++;

} while(x <= 10);

return y;

29.   

Analyse the following program segment and determine how many times the loop will be executed and what will be the output of the program segment?

int p=200;

while(true)

{

  if(p<100)

    break;

   p=p-20;

}

System.out.println(p);

30.   

Give the output of the following program segment:

Double x=2.9, y=2.5;

System.out.println(Math.min(Math.floor(x),y));

System.out.println(Math.max (Math.ceil (x),y));

31.   

What is the final value of ctr after the iteration process given below, executes?

int ctr = 0;

for (int i = 1 ; i < = 5 ; i++)

for (int j = 1 ; j < = 5 ; j+=2)

++ctr;

32.   

What are the values stored in variables r1 and r2:

(i)                 double r1 = Math.abs(Math.min(-2.83,-5.83));

(ii)               double r2 = Math.sqrt(Math.floor(16.3));

33.   

Rewrite the following program segment using if-else statements instead of the ternary operator.

String grade=(mark>=90) ? “A” : (mark>=80) ? “B” : “C”;

34.   

Write the output of the following code segment:

char ch;

int x = 97;

do

{

    ch = (char)x;

    System.out.print(ch+“ ”);

    if(x%10==0)

          break;

           ++x;

 } while(x<=100);

35.   

Analyze the given program segment and answer the following questions:

(i)                 Write the output of the program segment.

(ii)               How many times does the body of the loop gets executed?

for(int m=5; m<=20; m+=5)

{

      if(m%3 == 0)

            break;

     else if(m%5 == 0)

            System.out.println(m);

           continue;

 }

36.   

Give the output of the following program segment and also mention the number of times the loop is executed:

int a,b;

for(a=6,b=4;a<=24;a=a+6)

{

       if(a%b= =0)

         break;

}

System.out.println(a);

 

37.   

Write the return data type of the following functions : random( )

38.   

What will be the output of the following program segments?

int a = 0;
if(a>0 && a<20)
a++;
else a– ;
System.out.println(a);

39.   

What will be the output of the following program segments?

int a= 5, b = 2,c;
if (a>b || a ! = b)
c = ++a+–b;
System.out.print(c+ “ ”+a+ “ ”+b);

40.   

Convert the following segment into equivalent for loop 
{
int i, 1=0;
while (i<=20)
System.out.print (i+“”);
1++;
}






Click Here to Download PDF form

No comments

Powered by Blogger.