Java: Variables, Input and Arrays

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Types and Arithmetic Operators
Objective: Dealing with data in C++ Agenda: Notes Essay Help.
Chapter 2: Using Data.
CSC 142 J 1 CSC 142 Arrays [Reading: chapter 10].
© 2011 Pearson Education, publishing as Addison-Wesley 1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 6 focuses.
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
1.2 Primitive Data Types and Variables
A: A: double “4” A: “34” 4.
More than just a song and dance.. They are objects that store primitive variable values: Integer – stores an int Double – stores a double Character –
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
DATA TYPES, VARIABLES AND CONSTANTS. LEARNING OBJECTIVES  Be able to identify and explain the difference between data and information  Be able to identify,
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
What will each of the following lines print? System.out.println("number" ); number645 System.out.println("number" + (6 + 4)+ 5); number105 System.out.println(6.
Input, Output and Variables GCSE Computer Science – Python.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
7 - Programming 7J, K, L, M, N, O – Handling Data.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Sections 10.1 – 10.4 Introduction to Arrays
Java for Beginners University Greenwich Computing At School DASCO
Chapter No. : 1 Introduction to Java.
Chapter 2 Elementary Programming
Chapter 4 – Fundamental Data Types
Documentation Need to have documentation in all programs
Agenda Warmup Finish 2.4 Assignments
[Array, Array, Array, Array]
Computer Science 3 Hobart College
Introduction to C++ October 2, 2017.
C++ Arrays.
Engineering Innovation Center
Chapter 2.
Advanced Programming Behnam Hatami Fall 2017.
Review Operation Bingo
Java for Beginners University Greenwich Computing At School DASCO
Chapter 7: Strings and Characters
نوع داده هاي انتزاعي Abstract Data Types
Chapter 2: Basic Elements of Java
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
int [] scores = new int [10];
ArrayLists.
Arrays .
Arrays.
Coding Concepts (Data- Types)
[Array, Array, Array, Array]
Code Refresher Test #1 Topics:
Variables In today’s lesson we will look at: what a variable is
CSC 142 Arrays [Reading: chapter 12].
Arrays October 6, 2006 ComS 207: Programming I (in Java)
Python Basics with Jupyter Notebook
Other types of variables
Primitive Types and Expressions
Unit 3: Variables in Java
Comparing Python and Java
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
Subtype Substitution Principle
Input, Variables, and Mathematical Expressions
Presentation transcript:

Java: Variables, Input and Arrays By: John Laban, Hasan Majid, Noah Ventura

Variables A variable is data given an identifier. Data that is stored in ram. A variable can have different data types. The variable can be referenced anywhere in the code.

Data Types Primitive Data Types: Integer (Int) - Can use mathematical operations. - Contains one whole number. Double - Can use mathematical operations. - Contains one number which can contain decimals. Boolean - Can be in a state of true or false. Char - Contains one letter. Non-Primitive Data Types: String - Largely used for words, sentences and other text based data. - Any numbers stored are non-mathematical. - Can be converted to a int, double, char array etc. - Can use manipulation commands. - Needs to have an imported String Class:

Input Programs use input to allow interaction between the user and the program. One form of input is the scanner. To import the scanner class use: You then need to create a Scanner object: After, use the method called “next” to get input from the user, varies per data type:

Arrays An array is a structure that can store multiple items of the same data type. An array has a fixed number of data items (called elements). Each element in an array has an assigned index value starting at 0. The size of the array is known when the array is initialized: Data stored in an element can be changed:

Dynamic Arrays Dynamic Arrays allow you to have an array in your program which can change size during runtime. Dynamic arrays are initialized with an ArrayList: Dynamic arrays use methods to edit the data: Good job

Displaying All Data in an Array -To print every element in a regular array use this code: -To print every element in a dynamic array use this code: