Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java: Variables, Input and Arrays

Similar presentations


Presentation on theme: "Java: Variables, Input and Arrays"— Presentation transcript:

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

2 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.

3 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:

4 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:

5 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:

6 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

7 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:


Download ppt "Java: Variables, Input and Arrays"

Similar presentations


Ads by Google