Computers annual rev output question
Computers annual rev output question
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;
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)
n=(3*++m)%4 if m = 5 Ans : n = 2
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
𝑥 +𝑦 +
3 𝑥𝑦 Ans:Math.pow(x, 3) + Math.pow(y,
3
3) + (x * y) / 3
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;
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();
}
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? 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);
}