IS 112 - Programming Fundamentals 1 (Lec) Date: September 14, 2012 - Array.

Slides:



Advertisements
Similar presentations
A Short Review Arrays, Pointers and Structures. What is an Array? An array is a collection of variables of the same type and placed in memory contiguously.
Advertisements

UNIT II DATA TYPES OPERATORS AND CONTROL STATEMENT 1.
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
1 Arrays, Strings and Collections [1] Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software Engineering.
Introduction to Java 2 Programming Lecture 5 Array and Collections.
Chapter 10 – Arrays and ArrayLists
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Introduction to Programming Overview of Week 2 25 January Ping Brennan
Introduction to Programming
Introduction to Programming
Introduction to Programming Java Lab 2: Variables and Number Types 1 JavaLab2 lecture slides.ppt Ping Brennan
Introduction to Programming Java Lab 5: Boolean Operations 8 February JavaLab5 lecture slides.ppt Ping Brennan
Introduction to Programming Java Lab 3: Variables and Number types 25 January JavaLab3.ppt Ping Brennan
Introduction to Programming
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
Two Dimensional Arrays and ArrayList
Chapter 8: Arrays.
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Programming Methodology (1). Implementing Methods main.
Firefly Synchronisation Java Demo in 1D Array. 1 Dimension Firefly in Java two neighbors 1. Initialization: 2.
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
Review BP Dari slide pak cahyo pertemuan 7 dan pertemuan 2 dengan sedikit modifikasi.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Computer Programming Lab(7).
Importing methods in the Java library. Previously discussed Method = a collection of statements that performs a complex (useful) task A method is identified.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Java POWERED BY: ARVIND DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING RADHA GOVIND GROUP OF INSTITUTIONS,MEERUT.
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Lecture 8 Instructor: Craig Duckett. Assignments TONIGHT Lecture 8 Assignment 2 Due TONIGHT Lecture 8 by midnight Monday, February 2 nd Lecture 10 Assignment.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Copyright 2010 by Pearson Education Building Java Programs Chapter 7 Lecture 7-2: Arrays as Parameters reading: , 3.3 self-checks: Ch. 7 #5, 8,
1 Various Methods of Populating Arrays Randomly generated integers.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Building Java Programs
Computer Programming Lab 8.
CS324e - Elements of Graphics and Visualization A Little Java A Little Python.
Arrays I Savitch Chapter 6.1: Introduction to Arrays.
Test 2 Jason Jenkins Lauren Sears Aaron Stricklin Brandon Wolfe Julie Alexander.
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
“Introduction to Programming With Java”
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
1. Define an array 1 Create reference arrays of objects in Java program 2 Initialize elements of arrays 3 Pass array to methods 4 Return array to methods.
Introduction to Computing Concepts Note Set 21. Arrays Declaring Initializing Accessing Using with Loops Sending to methods.
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Chapter 2 Clarifications
CSC111 Quick Revision.
Arrays in JAVA Visit for more Learning Resources.
Introduction to Methods in java
Something about Java Introduction to Problem Solving and Programming 1.
Introduction to Classes and Methods
class PrintOnetoTen { public static void main(String args[]) {
Chapter 2: Java Fundamentals
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Presentation transcript:

IS Programming Fundamentals 1 (Lec) Date: September 14, Array

Array An Array is a collection (sequence ) of a fixed number of variables called elements or components, wherein all the elements are of the same data type. dataType [ ] arrayname = new dataType[noElements];

The Statement: Declares and creates the array num cosisting of 5 elements. Each elements are acceed as num[0], num[1], num[2], num[3], num[4]. int [ ] num = new int [5];

import java.util.Scanner; public class arraydemo1 { public static void main(String[]args) { Scanner keyboard=new Scanner(System.in); int noofEl; System.out.println("How many elements of array: "); noofEl = keyboard.nextInt(); int [] num = new int[noofEl]; int i, sum=0, prod=1, ave=0; System.out.println("Enter "+noofEl+" nos: "); for(i=0;i<noofEl;i++) { num[i]=keyboard.nextInt(); sum = sum + num[i]; prod = prod * num[i]; } for(i=0;i<noofEl;i++) System.out.println("Number "+(i+1)+": "+ num[i]); System.out.println("Sum: "+sum); System.out.println("Product: "+prod); System.out.println("Average: "+(sum/noofEl)); }