Output Programs These slides will present a variety of small programs. Each program has some type of array that was introduced in this chapter. Our concern.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Introduction to Java 2 Programming Lecture 5 Array and Collections.
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,
Session 3 Algorithm. Algorithm Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm Example Check.
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.
Quick Sorting -Ed. 2. and 3.: Chapter 10 -Ed. 4.: Chapter 11.
15 Sorting1June Sorting CE : Fundamental Programming Techniques.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Sorting Arrays. Selection Sort  One of the easiest ways to sort the elements of an array is by using the selection sort algorithm.  Assume that the.
Computer Programming Lab(5).
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.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
1 Linear and Binary Search Instructor: Mainak Chaudhuri
1 Chapter 8 Multi-Dimensional Arrays. 2 1-Dimentional and 2-Dimentional Arrays In the previous chapter we used 1-dimensional arrays to model linear collections.
First Data Structure Definition A data structure is a data type whose components are smaller data structures and/or simple data types.
Chapter 9: Arrays J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Answers to Assignment #1 (Assignment due: Wed. Feb. 05, 2003) 1. What does the "plateform independence" mean? How is it implemented in Java? 2. Summarize.
BUILDING JAVA PROGRAMS CHAPTER 2 Days of For Loops Past.
Java Arrays and Methods MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
The Bubble Sort by Mr. Dave Clausen La Cañada High School.
Chapter 4 Practice cont.. Practice with nested loops 1.What will be the output of the following program segment: 1.for (int i = 1; i
Sorting Algorithms: Selection, Insertion and Bubble.
***** SWTJC STEM ***** Chapter 7 cg 50 Arrays as Parameters Regular variables are passed to a method by value; i.e., the variable value is copied to a.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
MCQ Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 (index 2) for the first time? a)recVehicles.set(3,
1 Insertion sort [ ] i=1 j=1 i=2 j=2 insert i=3 at j=1 [ ] i=3 j=1 insert i=4 at j=0 [
1 BUILDING JAVA PROGRAMS CHAPTER 7.2 ARRAY TRAVERSAL ALGORITHMS.
Java Methods 11/10/2015. Learning Objectives  Be able to read a program that uses methods.  Be able to write a write a program that uses methods.
Chapter 6 Arrays 1 Fall 2012 CS2302: Programming Principles.
PreAP Computer Science Quiz Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 30 – 60 seconds.
Java Programming: Chapter 9: Arrays
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
1 Arrays: Matrix Renamed Instructor: Mainak Chaudhuri
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
Output Programs These slides will present a variety of small programs. Most of the programs deal with DecimalFormat objects or Polygon objects. Our concern.
1 Arrays Chapter 8. Objectives You will be able to Use arrays in your Java programs to hold a large number of data items of the same type. Initialize.
Array Review Selection Sort Get out your notes.. Learning Objectives Be able to dry run programs that use arrays Be able to dry run programs that use.
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern.
1 Why do we need arrays? Problem - Input 5 test scores => int test1,test2,test3,test4,test5 100 test scores? 10,000 employees? A structured data type is.
MC Question Strategies
Exercise Java programming
Advanced Programming TA Session 2
using System; namespace Demo01 { class Program
More on Recursion.
CS Week 7 Jim Williams, PhD.
March 29th Odds & Ends CS 239.
TO COMPLETE THE FOLLOWING:
An Introduction to Java – Part I, language basics
CS110D Programming Language I
CS2011 Introduction to Programming I Methods (II)
class PrintOnetoTen { public static void main(String args[]) {
slides created by Ethan Apter
Binary Search class binarysearch {
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Dry Run Practice Use Methods with an Insertion Sort
Object Oriented Programming
Take out a piece of paper and PEN.
Take out a piece of paper and PEN.
PowerPoint Presentation Authors of Exposure Java
PowerPoint Presentation Authors of Exposure Java
Take out a piece of paper and PEN.
Take out a piece of paper and PEN.
Question 1a) What is printed by the following Java program? int s;
PowerPoint Presentation Authors of Exposure Java
Array Review Selection Sort
Presentation transcript:

Output Programs These slides will present a variety of small programs. Each program has some type of array that was introduced in this chapter. Our concern will be with the output of each program, and more importantly, develop some methods to determine program output correctly, for programs that involves arrays. You can expect that on quizzes and/or tests only a program segment or a method is shown.

public class Ex1201 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; System.out.println(list[1]); }

public class Ex1202 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; for (int index = 1; index <= 9; index++) System.out.println(list[index]); }

public class Ex1203 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; for (int index = 0; index < 9; index++) System.out.println(list[index]); }

public class Ex1204 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1205 { public static void main (String args[]) { int list[] = new int[10]; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1206 { public static void main (String args[]) { int list[] = new int[10]; list[0] = 9999; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1207 { public static void main (String args[]) { int list[] = new int[10]; list[1] = list[3] = list[5] = list[7] = list[9] = 9999; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1208 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; list[1] = list[3] = list[5] = list[7] = list[9] = 9999; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1209 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; list[1] = list[3] = list[5] = list[7] = 9999; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1210 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; list[1] = list[3]; list[5] = list[7]; list[8] = list[6]; list[2] = list[0]; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1211 { static int list[] = {11,99,22,88,33,77,44,66,55}; public static void main (String args[]) { swap(3,1); swap(7,5); swap(6,8); swap(0,2); displayArray(); } public static void swap(int a, int b) { list[a] = list[b]; list[b] = list[a]; } public static void displayArray() { // Precondition: list is a non-empty Java static array of integers System.out.print("[" + list[0]); for (int index = 1; index < list.length; index++) System.out.print(", " + list[index]); System.out.println("]"); }

public class Ex1212 { static int list[] = {11,99,22,88,33,77,44,66,55}; public static void main (String args[]) { swap(3,1); swap(7,5); swap(6,8); swap(0,2); displayArray(); } public static void swap(int a, int b) { int temp = list[a]; list[a] = list[b]; list[b] = temp; } public static void displayArray() { // Precondition: list is a non-empty Java static array of integers System.out.print("[" + list[0]); for (int index = 1; index < list.length; index++) System.out.print(", " + list[index]); System.out.println("]"); }

public class Ex1213 { public static void main (String args[]) { int list[] = new int[10]; qwerty(list,5); displayArray(list); } public static void qwerty(int array[], int item) { for (int index = 0; index < array.length; index++) array[index] = item; } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1214 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; qwerty(list,5); displayArray(list); } public static void qwerty(int array[], int item) { for (int index = 0; index < array.length; index++) array[index] = item; } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1215 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; qwerty(list,5); list[5] = 9999; displayArray(list); } public static void qwerty(int array[], int item) { for (int index = 0; index < array.length; index++) array[index] = item; } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1216 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; list[1] = list[2] + list[0]; list[8] = list[7] + list[6]; list[5] = list[8] - list[1]; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1217 { public static void main (String args[]) { int list1[] = {11,99,22,88,33,77,44,66,55}; int list2[] = new int[100]; System.out.println(list1.length); System.out.println(list2.length); }

public class Ex1218 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; for(int index = 0; index < list.length; index++) list[index]++; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1219 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; list[1] = list[2] + list[0]; int x = 1; if (list[1] == list[4]) x = 11; for(int index = 0; index < list.length; index++) list[index] /= x; displayArray(list); } public static void displayArray(int array[]) { // Precondition: array is a non-empty Java static array of integers System.out.print("[" + array[0]); for (int index = 1; index < array.length; index++) System.out.print(", " + array[index]); System.out.println("]"); }

public class Ex1220 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; System.out.println(list[list.length]); System.out.println(list[list.length - 1]); }

public class Ex1221 { public static void main (String args[]) { int list[] = {11,99,22,88,33,77,44,66,55}; System.out.println(list[list.length - 1]); }