Computer Science, asked by 04arkgaming, 5 months ago

Q.10 Write output of the following and show the working also:[7]
1. int m=9,n=8;
for(int i=1;i<=15;i=i+3)
{ m--;
n++;}
System.out.println("m is ="+m);
System.out.print(" n is ="+n);
2. System.out.println(Math.min(-14,-23));
System.out.println(Math.pow(5,4));
System.out.print(Math.sqrt(144));

Answers

Answered by anindyaadhikari13
0

\star\:\:\:\sf\large\underline\blue{Question:-}

  • Write the output of the following code and show the working.

\star\:\:\:\sf\large\underline\blue{Solution:-}

Question 1:-

Given code:-

---------------------

int m=9,n=8;

for(int i=1;i<=15;i=i+3

{

m--;

n++;

}

System.out.println("m is ="+m);

System.out.print(" n is ="+n);

At first, the value of m is 9 and that of n is 8.

Now, the loop executes five times and after each execution, m is Decremented and n is incremented.

So, m=9-5=4

n=8+5=13.

So, it will print:-

m=4

n=13

Question 2:-

Given code:-

----------------------

System.out.println(Math.min(-14,-23));

System.out.println(Math.pow(5,4));

System.out.print(Math.sqrt(144));

Here,

Math.min(-14,23) returns -23 since -23 is smaller than -14.

Also, Math.pow(5,4)=5^4 =625.0

And, Math.sqrt(144)=12.0

So,

Output is:-

-23

625.0

12.0

\star\:\:\:\sf\large\underline\blue{Output:-}

For first question, output will be

m=4

n=13

For the second question, output will be,

-23

625.0

12.0

Similar questions