Variables variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell.

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 2: Primitive Data and Definite Loops.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
INTRODUCTION TO PYTHON PART 2 INPUT AND OUTPUT CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
CS305j Introduction to ComputingPrimitive Variables 1 Topic 4 Variables “Once a programmer has understood the use of variables, he has understood the essence.
Building Java Programs Chapter 2 Primitive Data and Definite Loops.
1 Variables. 2 Receipt example What's bad about the following code? public class Receipt { public static void main(String[] args) { // Calculate total.
1 Building Java Programs Chapter 2: Primitive Data and Definite Loops These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
1 Java Basics: Data Types, Variables, and Loops “ If debugging is the process of removing software bugs, then programming must be the process of putting.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
ADMIT TICKET WHAT DOES THIS OUTPUT? double y = 2.5; int x = 6 / (int) y; System.out.println(“x = “ + x);
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Building Java Programs Chapter 2 Primitive Data and Definite Loops.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
1 Building Java Programs Chapter 2: Primitive Data and Definite Loops.
Topic 4 Expressions and variables Based on slides bu Marty Stepp and Stuart Reges from "Once a person has understood.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
Chapter 9 Repetition.
Data Type and Function Prepared for CSB210 Pemrograman Berorientasi Objek By Indriani Noor Hapsari, ST, MT Source: study.
Building Java Programs Chapter 2
Lecture 4: Expressions and Variables
Building Java Programs
Lecture 2: Operations and Data Types
Primitive Data, Variables, Loops (Maybe)
Building Java Programs Chapter 2
Chapter 5 Repetition.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Building Java Programs Chapter 2
Topic 4 Expressions and variables
Building Java Programs Chapter 2
Chapter 9 Control Structures.
Lecture 3: Expressions and Variables
Building Java Programs
Building Java Programs
LOOPS BY: LAUREN & ROMEO.
CSc 110, Spring 2018 Lecture 5: The for Loop and user input
Topic 4 Expressions and variables
Building Java Programs
Building Java Programs
Variables variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell.
Building Java Programs Chapter 2
Building Java Programs
Lecture 5: Basic Java Syntax AP Computer Science Principles
Building Java Programs
Building Java Programs
CSE 190D, Winter 2013 Building Java Programs Chapter 2
Building Java Programs
Chapter 2 Programming Basics.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Lecture 4: Expressions and Variables
Building Java Programs
Building Java Programs
Building Java Programs
C Programming Pointers
Building Java Programs
How to fix Juno Error code 49? Dial: +1(844)
Building Java Programs
Building Java Programs Chapter 2
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Topic 4 Expressions and variables
Building Java Programs
Introduction to Pointers
Presentation transcript:

Variables variable: A piece of the computer's memory that is given a name and type, and can store a value. Like preset stations on a car stereo, or cell phone speed dial: Steps for using a variable: Declare it - state its name and type Initialize it - store a value into it Use it - print it or use it as part of an expression 5

Compiler errors A variable can't be used until it is assigned a value. int x; System.out.println(x); // ERROR: x has no value You may not declare the same variable twice. int x; int x; // ERROR: x already exists int x = 3; int x = 5; // ERROR: x already exists How can this code be fixed?

Loop walkthrough 1 2 4 for (int count = 1; count <= 4; count = count + 1) { System.out.println("Hello World!"); } System.out.println("Whoo!"); Output: Hello World! Whoo! 3 5 1 2 3 4 5