AP Java Warm-up Boolean Array.

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

Sorting algorithms Sieve of Eratosthenes
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
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);
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Musical Chairs No more than 2 people at one table who have been at the same table before. I suggest that one person remain at the table you have been at.
Finding factors of a number Use the beans to find factors of 24  Count out 24 beans  We know that products can be illustrated using a rectangular model.
Make a list with your group How can I remember???
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
March 24, 2009 The road to success is dotted with many tempting parking places. ~Author Unknown.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
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.
Unit 171 Algorithms and Problem Solving - II Algorithm Efficiency Primality Testing Improved Primality Testing Sieve of Eratosthenes Primality Testing.
Introduction to Java. Main() Main method is where the program execution begins. There is only one main Displaying the results: System.out.println (“Hi.
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
BUILDING JAVA PROGRAMS CHAPTER 2 Days of For Loops Past.
Sieve of Eratosthenes. The Sieve of Eratosthenes is a method that.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Mixing integer and floating point numbers in an arithmetic operation.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
GREATEST COMMON FACTORS
An introduction to arrays, continued. Recall from last time… public static void main ( String args[] ) { //define number of rooms final int N = 100; //define.
Data Structures Arrays and Lists Part 2 More List Operations.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Staples are our staple Building upon our solution.
A prime number is a whole number which only has two factors: one and itself. A prime number is a whole number which only has two factors: one and itself.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Sophomore Scholars Java
Searching and Sorting Searching algorithms with simple arrays
Linked Data Structures
Exercise Java programming
Chapter 6 More Conditionals and Loops
Maha AlSaif Maryam AlQattan
Grow these factor bugs, their legs
Mid Term Review Advanced Programming Ananda Gunawardena
Using The Sieve of Eratosthenes
Sieve of Eratosthenes.
Decision statements. - They can use logic to arrive at desired results
Computing Adjusted Quiz Total Score
OPERATORS (2) CSC 111.
March 29th Odds & Ends CS 239.
Selection Sort Find the smallest value in the array. Put it in location zero. Find the second smallest value in the array and put it in location 1. Find.
An Introduction to Java – Part I, language basics
Interfaces and Constructors
Java Language Basics.
Outline Late Binding Polymorphism via Inheritance
Prime Numbers and Prime Factorization
PRIME FACTORIZATION USING FACTOR TREES!.
class PrintOnetoTen { public static void main(String args[]) {
Sieve of Eratosthenes The Sieve of Eratosthenes uses a bag to find all primes less than or equal to an integer value n. Begin by creating a bag an inserting.
Dry Run Practice Use Methods with an Insertion Sort
CSS161: Fundamentals of Computing
CIS265/506 Simple Sorting CIS265/506: Chapter 03 - Sorting.
Common Array Algorithms
Debugging Exercise 00 Try compiling the code samples.
Prime Numbers.
Question 1a) What is printed by the following Java program? int s;
Sorting and Searching -- Introduction
Array Review Selection Sort
Topic 25 - more array algorithms
Methods/Functions.
Introduction to java Part I By Shenglan Zhang.
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Presentation transcript:

AP Java Warm-up Boolean Array

public static void main ( String[] args ) int[] val = {0, 1, 2, 3}; class Exercise5 { public static void main ( String[] args ) int[] val = {0, 1, 2, 3}; int temp; System.out.println( "Original Array: " + val[0] + " " + val[1] + " " + val[2] + " " + val[3] ); // write the code to reverse the order of the numbers in the array System.out.println( "Reversed Array: " + val[0] + " " + val[1] + " " + val[2] + " " + val[3] ); }

Warm up Array Reading Common Array Algorithms Link Complete the fill in blanks on the web pages Take notes as needed.

Boolean Array Program (11/2/2015) Show all prime numbers <=1000 Use the sieve of Eratosthenes Write a program to use this process in finding all primes less than or equal to 1000. How many primes will Java let you find using this method? Cross out 1, because it is not prime. Circle 2, because it is the smallest positive even prime. Now cross out every multiple of 2; in other words, cross out every second number. Circle 3, the next prime. Then cross out all of the multiples of 3; in other words, every third number. Some, like 6, may have already been crossed out because they are multiples of 2. Circle the next open number, 5. Now cross out all of the multiples of 5, or every 5th number. Continue doing this until all the numbers through 100 have either been circled or crossed out. You have just circled all the prime numbers from 1 to 100!

Getting Started Creating an array of Booleans boolean[] seive = new boolean[1000]; Initializing them to true (potentially prime). for( int i = 0; i < seive.length; i++ ) seive[i] = true ;