Selection Structures and Temperature Conversion in Various Programming Paradigms

Selection Structures and Temperature Conversion in Various Programming Paradigms
Slide Note
Embed
Share

Pseudocode examples and Java implementations showcasing IF, IF-ELSE, and IF-ELSE-IF structures for temperature conversion. Understand how to convert Celsius to Fahrenheit and provide different outputs based on the temperature range. Enhance your programming skills with these practical examples.

  • Programming
  • Pseudocode
  • Java
  • Conditional Statements
  • Temperature Conversion

Uploaded on Feb 22, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Selection Structures

  2. Pseudocode - IF Statement MAIN Fahrenheit = 0, Celsius = 0 PRINT Enter Celsius temperature: READ user input Celsius = user input Fahrenheit = 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT heat warning Ps ENDIF END MAIN

  3. Java Example - if Statement import java.util.Scanner; public class CelsiusToFahrenheit { public static void main (String[] args) { double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print ( What is the Celsius temperature? "); celsius = scan.nextDouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println ( The temperature is " + fahrenheit + degrees Fahrenheit ); if (fahrenheit >= 90) { System.out.println( It is really hot out there! ); } } }

  4. Pseudocode IF-ELSE Statement MAIN Fahrenheit = 0, Celsius = 0 PRINT Enter Celsius temperature: READ user input Celsius = user input Fahrenheit = 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT heat warning ELSE PRINT there is no extreme heat Ps ENDIF END MAIN

  5. Java Example if-else (code snippet) double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print ( What is the Celsius temperature? "); celsius = scan.nextDouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println ( The temperature is " + fahrenheit + degrees Fahrenheit ); if(fahrenheit >= 90) { System.out.println( It is really hot out there! ); } else { System.out.println( There is no extreme heat today. ); }

  6. Pseudocode IF-ELSE-IF MAIN Fahrenheit = 0, Celsius = 0 PRINT Enter Celsius temperature: READ user input Celsius = user input Fahrenheit = 9.0 / 5.0 * Celsius + 32 PRINT Fahrenheit IF (Fahrenheit > = 90) THEN PRINT heat warning ELSE IF (Fahrenheit >= 80) THEN PRINT it is warm, but there is no extreme heat ELSE IF (Fahrenheit >= 70) THEN PRINT the temperature is pleasant and suggest a picnic ELSE PRINT a suggestion to take a jacket END IF END MAIN Ps

  7. Java Example if-else-if double celsius= 0.0, fahrenheit = 0.0; Scanner scan = new Scanner (System.in); System.out.print ( What is the Celsius temperature? "); celsius = scan.nextDouble(); fahrenheit = 9.0 / 5.0 * celsius + 32; System.out.println ( The temperature is " + fahrenheit + degrees Fahrenheit ); if (fahrenheit >= 90){ System.out.println( It is really hot out there! ); } else if (fahrenheit >= 80) { System.out.println( It is very warm... ); } // CONTINUED ON NEXT SLIDE

  8. Java Example if-else-if (cont) else if (fahrenheit >= 70) { System.out.println( It is very pleasant today! ) } else { System.out.println( It is cool today. Take a jacket. ); }

  9. Pseudocode switch Statement // Read user input like before conditions = compute using Fahrenheit variable / 10 CASE conditions OF 10 9 8 7 DEFAULT : : : : : PRINT stay inside , BREAK PRINT be careful due to heat , BREAK PRINT it is hot, but not extreme , BREAK PRINT pack a picnic , BREAK PRINT take a jacket , BREAK ENDCASE Ps

  10. Java switch Example int condition = (int)fahrenheit / 10; System.out.println("It is in the " + condition + 0's."); switch (condition) { case 10: break; case 9: System.out.println("It is really hot out there!"); break; case 8: System.out.println("It s warm, but no extreme heat!"); break; case 7: System.out.println("It is very pleasant today!"); break; default: System.out.println("Take a jacket!"); break; } System.out.println("Stay inside!");

More Related Content