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
Imagine the user types in a complete sentence, but we want to read only the first word and place it in the String variable word.
Vladimir [108]

Answer:

import java.util.Scanner;

public class FirstWord {

   public static void main(String[] args) {

       //NOW YOU WANT TO COLLECT INPUTS FROM THE STUDENT OR USER

       //IMPORT THE SCANNER CLASS FIRST  outside your class

       // THEN YOU CREATE AN OBJECT OF THE SCANNER CLASS

       Scanner input = new Scanner(System.in);

       

       //CREATE A VARIABLE TO HOLD THE USER INPUT

       String text = input.nextLine();

       

       //The variable holder will be used to store characters from the for loop

       String holder="";

       

       //Create a for loop that loops through the user's input

       for(int i=0; i<text.length(); i++){

           //As the loop increases, we get the character in the user's input and store them one by one in the variable holder

           holder+=text.charAt(i);

           if(text.charAt(i)==' '){

               //If the loop encounters a space, it means a complete word has been gotten from the user's input

               //Then the break below Breaks the loop, and the loop stops running

               break;

           }

       }

       System.out.println(holder);

}

Explanation:

text.length() returns the length of the sequence of characters present in length

text.charAt(a number) Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

Create a for loop

How does a for loop work?

It collects a starting point, an end point and an increment respectively....all these are passed in as arguments into the for loop

For example, the code above starts from 0, calculates the number of characters in the user's input and sets it as the end point, the loop runs from zero to the length of the text of the user...

Note: i++ in the loop is the increment, it means the loop increases by 1

8 0
3 years ago
Speed is how fast an object moves a certain distance within a length of time. How is speed calculated?
Butoxors [25]

I believe the answer to be A) because distance with the time it took to to reach the distance would determine how speed is to be calculated.

4 0
3 years ago
Read 2 more answers
List 10 programs or applications on your computer other than any Microsoft office programs
Fofino [41]
Dropbox
Mozilla Firefox, Google Chrome
Gmail, Mozilla Thunderbird
CDburnerXP
Putty, Netflix,
Paint.net, Filezilla
3 0
2 years ago
There is a development team delivering a new software package with agile and devops frameworks. in one of the releases, the auto
Olin [163]

A practice that should be implemented in the aforementioned situation is to separate the Agile and DevOps software development framework.

<h3>What is a unit test?</h3>

A unit test can be defined as an automated test that's typically written and run by a software developer, so as to ensure that a section (component) of a software application meets its design specifications, functionalities and requirements.

In this scenario, a practice that should be implemented by the software developer is to separate the Agile and DevOps software development framework.

Read more on unit test here: brainly.com/question/22900395

#SPJ1

4 0
2 years ago
Read 2 more answers
Ten(10) examples of wearables or wearable technologies?​
Semmy [17]

Answer:read

Explanation:

airpods

headphones

earbuds

AirPods  pro

watch

fitbit (type of watch that counts your miles) &you can say workout watch&

VR set

technology bracelet

smart glasses

Smart ring

7 0
3 years ago
Other questions:
  • In Paint, which of the following are ways to use a picture that you have saved on your computer? (Select all that apply.)
    8·1 answer
  • Driving while wearing headphones or earphones
    12·2 answers
  • Write the code that creates a public class named Vehicle that has one private data member. The private data member is an integer
    13·1 answer
  • Professionals within the creative imaging fields must have which of the following items to showcase technical expertise?
    14·2 answers
  • How many pieces are there in a normal laptop??? Good luck and solve carefully
    9·1 answer
  • Help me find the difference between these logos
    10·2 answers
  • Which method is used for resolving data dependency conflict by the compiler itself?
    6·1 answer
  • What is the mest gun in pixel gun 3d imma give you brainliest
    14·2 answers
  • The advancement in speed of transportation is attributed to invention of this device
    8·1 answer
  • please help me to do this computer homework I beg you all please help me to get the answers please its important please ​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!