1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gekata [30.6K]
3 years ago
7

What is output by the following C# code segment?int temp;temp = 180;while ( temp != 80 ) {if ( temp > 90 ) {Console.Write( "T

his porridge is too hot! " );// cool downtemp = temp – ( temp > 150 ? 100 : 20 ); } // end ifelse {if ( temp < 70 ) {Console.Write( "This porridge is too cold! ");// warm uptemp = temp + (temp < 50 ? 30 : 20);} // end if} // end else} // end whileif ( temp == 80 )Console.WriteLine( "This porridge is just right!" );
Computers and Technology
1 answer:
Artemon [7]3 years ago
7 0

Answer:

This porridge is too hot! This porridge is just right!

Explanation:

I am going to explain every line of the given C# code to give explanation of the output.

  • The first statement int temp declares a variable temp.
  • Then the temp variable is assigned a value 180.
  • The block of statement in while loop body will keep executing until the value in temp variable gets equal to 80. The while loop first checks if the value of temp is not equal to 80. As the value of temp=180 which is not equal to 80, this means that the condition of while loop evaluates to true so the block of code in the body of the loop is reached.
  • There is an if condition inside while loop which checks if the value in temp variable is greater than 90. As value of temp=180 which is greater than 90 so the condition is true.
  • As the condition in the if statement evaluates true so the block of code which is the part of this if statement will be executed:

             {Console.Write( "This porridge is too hot! " );

                  temp = temp – ( temp > 150 ? 100 : 20 ); }

  • The first statement is executed which displays this message: This porridge is too hot!
  • Next   temp = temp – ( temp > 150 ? 100 : 20 ); statement will change the value of temp. It has the conditional operator which works as follows:

                 Here, temp>150 is the condition to be evaluated.

  • If this condition is True then 100 will be returned else 20 will be returned. The value returned is then subtracted from the value of temp and the subtraction result will become the new value of temp. As the value of temp which is 180 is greater than 150 so 100 is returned and is subtracted from the value of temp (180).

                                        temp= 180-100

                                             temp=80

  • So the new value of temp is 80.
  • The else part will not be executed because the condition in if statement was true and also we can see that temp is not less than 70. It means that the porridge is too cold part will not be executed.
  • The while loop while(temp!=80) will again be checked. As the new value of temp is now 80, so the condition gets false which breaks the while loop and program control will leave the body of while loop.
  • After the control comes out of the while loop, there is another if statement. This statement checks if the value of temp variable is equal to 80. It is true as the new value of temp is now 80 after that execution of while loop block of code.
  • As the if condition evaluates to true the statement

                    Console.WriteLine( "This porridge is just right!" );

       will be executed which displays the message:

                                  This porridge is just right.

  • Hence the output of the given code is:

           This porridge is too hot! This porridge is just right!

You might be interested in
How much cell phone data does the average person use a month
azamat
It all depends on what you're doing online.
7 0
3 years ago
Which microsoft operating system started the process of authenticating users with a user name and password?
11111nata11111 [884]
It should be either windows 98 or windows xp but I think it is windows xp
5 0
3 years ago
The internet may best be compared to a
liraira [26]
I would say a calculator.
7 0
3 years ago
Read 2 more answers
You recently completed a network overhaul over the weekend. Everything seems to be functioning properly until you receive a swar
ZanzabumX [31]

Answer:

Network switch has been disconnected or switched off

Explanation:

An organization networking can be done by using several switches, routers, modems, etc. A network switch works between modem and systems, connecting the systems to the network.

A network switch is a multi-port switch that connects multiple devices to the network. mostly every floor has a network switch connected with the floor systems.

When a system is connected to switch, its indicator light on NIC is active. but as per the scenario, no system has active indicator lights on NIC, which means that there is some problem with the switch or switch is powered off.

4 0
3 years ago
If my beats by Dre are lighter does that mean they are fake because they feel really light. I have the Solo 3 wireless
lubasha [3.4K]

Answer:

yess

Explanation:

4 0
3 years ago
Other questions:
  • WHOEVER HELPS ASAP GETS BRAINLiEST!!!!!!!!! :)
    15·2 answers
  • Analyze the following code. II: public class Test { public static void main(String[] args) { System.out.println("Welcome to Java
    11·1 answer
  • A short-circuit evaluation is where each part of an expression is evaluated only as far as necessary to determine whether the en
    14·1 answer
  • How to insert header and page number in word 2016?
    8·1 answer
  • which of the following is not a step of the scientific method A.identifying the problem B.making observations C. making a hypoth
    15·1 answer
  • Computer is created by aliens?!
    14·1 answer
  • ​if a primary key combines two or more fields, then it is called a _____.
    14·1 answer
  • One common method of converting symbols into binary digits for computer processing is called ASCII​ (American Standard Code of I
    5·1 answer
  • In order to organize your work effectively on the computer, where is the best place to save it?
    14·2 answers
  • ​Lara is the chief editor of "Laughter and Life," an online magazine. Lara has assigned Jenny the task of redesigning the magazi
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!