# ex3 - This places the value // into the celsius variable...

This preview shows page 1. Sign up to view the full content.

Example 3: Decision Making: Equality and Relational Ops – Sec 2.8 /* class ConvertTemperature * * Purpose: Same as example 2, but with conditional statements * */ import java.util.Scanner; // use the Java built-in class Scanner public class ConvertTemperature { /* main * * The main method begins any Java program * This method prints a message to the screen. */ public static void main(String[] args) { // tell Java that we want some numbers (integers) to use int celsius; int fahrenheit; Scanner input; // create Scanner so that we can read from the screen input = new Scanner( System.in ); // print a message to the screen System.out.println("Enter the number you want to convert to F"); // the scanner reads the user’s value.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: This places the value // into the celsius variable celsius = input.nextInt(); // calculate the result fahrenheit = ((celsius * 9) / 5) + 32; // print out the result System.out.printf("%d degrees Celsius = %d degrees Fahrenheit\n", celsius, fahrenheit); // see if it is freezing if (fahrenheit <= 32) { System.out.println("Brrrr. That is freezing!"); } // see if it is really, really hot if (fahrenheit >= 100) { System.out.println("Yikes! What a scorcher!"); } } // end of main } // end of class ConvertTemperature Choices for comparing two integers: < less than > greater than <= less than or equal to >= greater than or equal to == equal to != not equal to...
View Full Document

## This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Ask a homework question - tutors are online