ex2a - variables have: name, type, value, memory location...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* class ConvertTemperature * * Purpose: show how to calculate values using integers */ 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 // these are called variables. Here, we declare our variables int celsius; int fahrenheit; // assign values to our variables - 30 is a literal celsius = 30; // calculate the result fahrenheit = ((celsius * 9) / 5) + 32; // print out the result System.out.printf("%d degrees Celsius = %d degrees Fahrenheit\n", celsius, fahrenheit); } // end of main } // end of class ConvertTemperature statement - a complete instruction that causes the computer to perform some action. int - the way we tell the computer we want to keep track of a piece of information, and that piece of information happens to be an integer (as opposed to a rational number) variables - named storage locations in memory reserved to store information
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: variables have: name, type, value, memory location declare a variable - specify the type and name of a variable for later use expression - ((Celsius * 9) / 5) + 32 - calculations that produces a result. assignment - "=" - statement that place the result of an expression into a variable. Names Variable names: Must begin with a letter (not a number), No spaces, no symbols other than '_' Additional Java convention: Must begin with a lower-case letter Name has something to do with its use Compound words use capitals for all but first word (i.e. myFirstVariable) Class names (The organizational unit for Java): The same requirements. The only difference is it begins with a capital letter. Questions about above code: What happens if we change the order of the calculation? For example, what if we replace this line: fahrenheit = ((celsius * 9) / 5) + 32; with this line: fahrenheit = celsius * (9 / 5) + 32;...
View Full Document

Page1 / 2

ex2a - variables have: name, type, value, memory location...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online