Changes between Initial Version and Version 1 of ControlSystems/SoftwareTeam/Training/GettingStarted/Variables


Ignore:
Timestamp:
Nov 4, 2019, 2:53:58 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/Variables

    v1 v1  
     1Let's try a slightly more complex program that will introduce variables.  A variable is like a box that can hold something for you.  In Java, you can put only one type of thing in a given box.  Variables can hold things like:
     2* An integer number (e.g. 42)
     3* A real number (e.g. 3.141592)
     4* A character (e.g. 'a' or '0' or '!')
     5* A string of characters (e.g. "Howdy")
     6* Something you define
     7
     8Variables are an important part of every program because they allow the program to do different things depending on what's in the box.
     9
     101. Close your current project if you have one open (File->Close Folder)
     112. Make a new folder in your Java Projects folder named !VariablesExample
     123. Open the folder (File->Open Folder)
     134. Create a new file: (File->New)
     145. Cut and paste the program below into the editor window:
     15{{{
     16public class VariablesExample {
     17    public static void main(String args[]) {
     18        int a;  // create a variable that can hold an integer number
     19        int b;  // create another integer variable named b
     20        int c;
     21
     22        a = 3;
     23        b = 4;
     24        c = a * b;
     25        System.out.println(c);
     26    }
     27}
     28}}}
     296. Save the file as !VariablesExample.java (File->Save)
     307. Run the program
     318. In the output terminal window, observe that the number 12 is output.
     32
     33=== Extra Credit ===
     34Change the program, adding more variables, changing numbers and formulas and run it again.