0% found this document useful (0 votes)
1 views

Computers annual rev output question

The document contains a series of programming questions and answers related to Java, focusing on output predictions, mathematical functions, and code conversions. It includes various code snippets, their expected outputs, and explanations of concepts such as ternary operators and loop constructs. The content is structured as a revision guide for Class IX Computer Applications, covering fundamental programming concepts and syntax.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Computers annual rev output question

The document contains a series of programming questions and answers related to Java, focusing on output predictions, mathematical functions, and code conversions. It includes various code snippets, their expected outputs, and explanations of concepts such as ternary operators and loop constructs. The content is structured as a revision guide for Class IX Computer Applications, covering fundamental programming concepts and syntax.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

ANNUAL REVISION

Class IX Subject: Computer Applications


OUTPUT QUESTIONS

What is the output of the following code :

Question Answer

State the values of n and ch after executing the following Ans: n=66;
code ch=B
char c=’A’;
int n=c+1;
char ch=(char)n;

int x=72; Ans: 72 H


char y=(char)x;
System.out.println(x+" "+y);

char c = ‘A’; Ans : The output of the code will


short m=26; be : 91
int n=c+m;
System.out.println(n);

Give the output for the following math functions: Ans: 81.0
a) Math.floor(81.2) Ans: -8.0
b) Math.ceil(-8.76) Ans: 29
c) Math.round(28.9) Ans:73.25
d) Math.abs(-73.25) Ans: 9.0
e) Math.sqrt(81) Ans:-8.0
Ans:5.0
f) Math.pow(-2,3)
g) Math.cbrt(125)

What will be the value of the following Ans : a = 49


int a=6,b=5;
a += a++ % b++ *a + b++* --b;

n=(3*++m)%4 if m = 5 Ans : n = 2

m=- - p+p*++n if p=10 and n=7 Ans: 81

int a=6,b=5,c; Ans: c = 55


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

int a=11, b=22, c; Ans: c =103 and a=13, b=24


c = a + b + a++ + b++ + ++a + ++b;

int i=19, j=29, k; Ans:k = -20 and i=19, j=29


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

int a=1; Ans : a= 5


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

i = i++ - --i + --i *i--; where i=20 Ans: i=361


Write the equivalent java expression for the following Ans. s= 5.0/10.0 + Math.pow(x,5)
mathematical expression + 5 * Math.pow(x, 3)
5 5 3
s= 10
+ 𝑥 +5𝑥

5
s= 𝑎𝑥 +𝑏𝑥 + c
3 Ans.a * Math.pow(x, 5) + b *
Math.pow(x, 3) + c

T=
2 2
(𝐴 + 𝐵 + 𝐶 )
2 Ans. T = Math.sqrt(Math.pow(A, 2)
+ Math.pow(B, 2) + Math.pow(C,
2));

𝑎 +𝑏
2 2
Ans.(Math.pow(a, 2) + Math.pow(b,
2𝑎𝑏 2)) / (2 * a * b)

3
X=|𝐴| + |𝐵| + (𝐴 + 𝐵 )
4 Ans: X=Math.abs(A)+ Math.abs(B)
+(Math.pow(A,3)+ Math.pow(B,4))

| 𝑎3+𝑏3 | Ans: s=
| 3 3|
| 𝑎 −𝑏 | Math.abs((a*a*a+b*b*b)/(a*a*a-b*b*
b))

3 𝑎+𝑏 Ans: s= Math.cbrt((a+b)/(a*b))


𝑎𝑏

3
𝑥 +𝑦 +
3 𝑥𝑦 Ans:Math.pow(x, 3) + Math.pow(y,
3
3) + (x * y) / 3

Rewrite the following using ternary operator: Ans.discount=(bill >10000 ) ? bill *


if (bill >10000 ) 10.0/100: bill * 5.0/100;
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;

Give the output of the snippet: Ans: 9 and 12


int a=10,b=12;
if(a==10&&b<=12)
a--;
else
++b;
System.out.println(a + " and " +b);

Give the output of the following code snippet: Output


int p = 9; 11
while (p<=15) 12
{ 13
p++; 14
if(p== 10) 15
continue; 16
System.out.println(p);
}
Predict the output and the number of times the loop runs: Output:Loop executes 5 times
class Test { 0
public static void main() { 0
int i; -2
for(i=0;i<5;i++) -6
System.out.println(i-i*i); -12
}
}

Evaluate the value of n if the value of p=5 and q=19: Ans.


int n = (q-p)>(p-q)?(q-p):(p-q); n=14

What are the values of x and y when the following Ans.x=false y=63
statements are executed?
int a = 63, b = 36;
boolean x = (a < b ) ? true : false;
int y= (a > b ) ? a : b;

Give the output of the following code when .


(i) opn = ‘b’ i. Online Tutor
(ii) opn = ‘x’ Online Courses
switch (opn) Invalid Input
{ ii. Invalid Input
case ‘a’:
System.out.println(“Simply Coding”);
break;
case ‘b’:
System.out.println(“Online Tutor”);
case ‘c’:
System.out.println(“Online Courses”);
default:
System.out.println(“Invalid Input”);
}

Rewrite the following program code using the suitable ‘if’ Ans:
statement if(m==0)
switch(m) {
{ x= x+2;
case 0: x=x+2; System.out.println(“X=” +x);
System.out.println(“X=” x); }
break; else if(m==1)
case 1: x=x+4; {
System.out.println(“X=” x); x= x+4;
break; System.out.println(“X=” +x);
case 2: x=x+6; }
System.out.println(“X=” x); if(m==2)
break; {
} x= x+6;
System.out.println(“X=” +x);
}
Give the output of the following program. Ans
int i,j; 0
for (i=0; i<4; i++) { 10
for (j=i; j>=0; j--) 210
System.out.print(j); 3210
System.out.println();
}

Convert the following do-while loop into for loop. Ans.


int i=1; for(int i=1, d=5; i<=5; i++)
int d=5; {
do d = d * 2;
{ System.out.println(d);
d=d*2 }
System.out.println(d);
i++;
}while(i<=5);

Write the output of the following code segment: Ans.


char ch; The output will be
int x = 97; abcd
do {
ch = (char) x;
System.out.print(ch + " ");
if (x % 10 == 0)
break;
++x;
} while (x <= 100);

Write an equivalent while() loop for the following for() loop. Ans.
int s=0; int x=1,s=0;
for(int x=1; x<=25; x+=2) while (x<=25){
s+=x; s +=x;
x+=2;
}

Write the output of the following code segment: Ans: WELCOME


class Java { JAVAPROGRAMMING
public void main(){
System.out.println("WELCOME");
System.out.print("JAVA");
System.out.println("PROGRAMMING");
}}

Write the output of the following code? Ans: no output will be produced.
int x=9;
int y=8;
Int z=7;
if(x>9)
if(y>8)
System.out.println(“x>9 and y>8”);
else if(z>=7)
System.out.println(“x<=9 and z>=7”);
else
System.out.println(“x<=9 and z<7”);
Write the output of the following code? Ans: 5
int term=0;
for(int i=1;i<=20;i++)
{
term =3*i+2;
if(term%4==0)
break;
System.out.println(term);
}

Write the output of the following code? Ans: Endless loop


int sum = 0;
int count =5;
while(count>1)
{
sum=sum+count;
count=count+2;
}
System.out.println(sum);

You might also like