/* Variables2.java CIS 160 David Klick 2015-09-02 Demonstration of using variables. */ public class Variables2 { public static void main(String[] args) { // Variables are named memory locations that store data. // We have to specify a name and data type to create a variable. // We have to declare a variable before we use it. // We have to initialize a variable before we try to use its value. // Declare a variable double sum; // this variable is not initialized // Declare and initialize variables double x; x = 3.4; double y = 8.9; // you can initialize at the same time you declare // Do some simple math // In this case x and y had to be initialized because we are using their values. // sum did not have to be initialized because we are setting its value. // The = is the assignment operator. Java calculates the value on the right // side of the = and stores the value in the variable on the left side. sum = x + y; // Display the result // System.out.println() is a method used to send something to the display. // You should see 12.3 when you run this program. System.out.println(sum); } }