L04 - Computer Science 1 1 SS C Lecture 4 Contents! 2!...

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

View Full Document Right Arrow Icon
CS101 Lecture 4 1 Computer Science 1 1 SS C Lecture 4 Contents Java has eight primitive types Storing information - variables The assignment statement Expressions Modulus Increment, decrement operators Coursebook: §4, §5 1 2 3 4 5 6 7 8 9 10 11 2 Review public class MyProgram { public void start() { System.out.print("abc\ndef"); System.out.println("\""); } } What is the output of the following two programs? abc def" public class MyProgram { public void start() { System.out.println("\\n\n\n\\n"); } } \n \n 3 Variables A variable is a section of memory that we can use to store some piece of information: • every variable has a name (identiFer), • each variable is only capable of holding one type of information, • each variable can only hold a single value at a time. 4 Variables X Variable Analogy • A variable is like a box with a label. • The box is shaped so that only one kind of thing Fts in it. • The box is able to hold one thing at a time. 5 Declaring a variable We must declare a variable before we can use it to store a value: int wholeNum ; int number ; double costPrice, rate, sellPrice ; • the declaration also speciFes the name of the variable. • the declaration speciFes what type of data the variable will store, ±or example: 6 Type of a primitive variable In JAVA, all variables have a type. Integers (whole numbers): float, double boolean char byte, short, int ,long, float, double, char, boolean byte, short, int , long ±loating-point numbers (decimal numbers): boolean (true or false): Characters (symbol in character set (text)): There are eight primitive types :
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS101 Lecture 4 2 7 Range of values allowed Values stored by integer and foating point types: Note: foat and double use scientiFc notation byte 8 bits -128 127 short 16 bits -32 768 32 767 int 32 bits -2 147 483 648 2 147 483 647 long 64 bits -9 223 372 036 854 775 808 9 223 372 036 854 775 807 double 64 bits +/- 4.9 E-324 +/- 1.8 E+308 Type Size Minimum Value Maximum Value float 32 bits
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2012 for the course COMPSCI 101 taught by Professor Adrianaferraro during the Summer '12 term at Auckland.

Page1 / 5

L04 - Computer Science 1 1 SS C Lecture 4 Contents! 2!...

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

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