Maximum value float 32 bits 14 e 45 34 e38 8 variable

This preview shows page 2 - 4 out of 5 pages.

Maximum Value float 32 bits +/- 1.4 E-45 +/- 3.4 E+38 8 Variable identifiers long dollarsOwnedByBillGates ; double percentagePassing101, percentagePassing105 ; int numberOfStudents ; boolean isTheLectureOverYet ; Examples • use sensible names that inform the programmer what the variable is used for. • all other letters should be lower case, • any subsequent words should start with a capital letter • all variable identifiers should begin with a lower case letter, Use the following style guidelines for ALL variable identifiers: 9 Assignment statements The assignment operator, = , is used to put a value into a variable e.g. X 37 x = 37; x = 37; int x; Assigns a value to the variable, i.e. puts the value into the box identified by the variable name. Both the variable and the value must be compatible types. The variable can only hold one value at a time – assigning a new value to a variable will replace any previous value. = 10 Declare and initialise a variable We can assign a value to a variable at the same time that we declare it. X 3 int x = 3; So instead of: we can simply have: x = 3; int x; 11 23 Printing variables A variable can be used anywhere that a literal can be used. 23 number System.out.println(number ); System.out.println( number ); int number = 23; will print out the value 23. We can print out the value stored in a variable using the System.out.println() statement, e.g. 12 Symbolic constants – final A symbolic constant is like a variable, except that the value it stores cannot change once it is initialised. A constant has to be initialised when it is defined. int DAYS_IN_YEAR = 365; Use the following style guidelines for naming symbolic constants: double GST_RATE = 0.125; • separate multiple words with an underscore For example • use all upper case letters
Image of page 2

Subscribe to view the full document.

CS101 Lecture 4 3 13 Expressions An expression is code that can be evaluated to give a single value: 35 Examples of Expressions a variable is an expression • a literal value is an expression Assume the variables age, number and value have been declared and initialised.
Image of page 3
Image of page 4
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, Natural number, public void, public class

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern