Java for Beginners University Greenwich Computing At School DASCO

Slides:



Advertisements
Similar presentations
Q1 Review. Other News US News top CS Universities global-universities/computer- science?int=994b08.
Advertisements

Programming Part 1 Armond R. Smith Zhenying Wu. Overview of this Class ● Transition from FTC -> FRC ● Using Your Resources ● Java Keywords o Data Types.
CSM-Java Programming-I Spring,2005 Control Flow Lesson - 3.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
* What kind of loop would I use to complete the following: A. Output all of the prime numbers that are less than 100,000 B. Output the Fibonacci sequence.
Java for Beginners University Greenwich Computing At School DASCO
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Lecture 2: Classes and Objects, using Scanner and String.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
New Tools And Workshop Mod & For Loops. Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
2016 N5 Prelim Revision. HTML Absolute/Relative addressing in HTML.
Conditionals Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignment? zPass by value limitations.
Jeopardy Print Me Which loop? Call Me Name Me My Mistake Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Week91 APCS-A: Java Problem Solving November 2, 2005.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
Java for Beginners University Greenwich Computing At School DASCO
Sophomore Scholars Java
7 - Programming 7J, K, L, M, N, O – Handling Data.
CSC 211 Java I for loops and arrays.
Basic concepts of C++ Presented by Prof. Satyajit De
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Java for Beginners University Greenwich Computing At School DASCO
Java for Beginners Level 6 University Greenwich Computing At School
Java for Beginners University Greenwich Computing At School DASCO
Week of 12/12/16 Test Review.
What’s cheating and what is not?
Java for Beginners.
Primitive Data, Variables, Loops (Maybe)
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
User input We’ve seen how to use the standard output buffer
Advanced Programming in Java
Java LESSON 2 Operators & Conditionals
Arrays An Array is an ordered collection of variables
Java for Beginners University Greenwich Computing At School DASCO
Java Fix a program that has if Online time for Monday’s Program
Java for Beginners University Greenwich Computing At School DASCO
Java for Teachers Intermediate
Coding Concepts (Sub- Programs)
Truth tables: Ways to organize results of Boolean expressions.
Topic 1: Problem Solving
Topic 1: Problem Solving
We’re moving on to more recap from other programming languages
Coding Concepts (Basics)
Announcements Exam 1 Thursday Everything through Lab 5 50 minutes
Truth tables: Ways to organize results of Boolean expressions.
Java Fix a program that has if Online time for Monday’s Program
Logical Operations In Matlab.
Coding Concepts (Data- Types)
Selection Statements.
Arrays.
Review for Test1.
Chapter 2 Programming Basics.
Java for Beginners University Greenwich Computing At School DASCO
CS2011 Introduction to Programming I Selections (I)
Java Programming Loops
Suggested self-checks: Section 7.11 #1-11
Lecture 13 Introduction to High-Level Programming (S&G, §§7.1–7.6)
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Announcements Lab 3 was due today Assignment 2 due next Wednesday
Welcome back! October 11, 2018.
Software Development Techniques
COMPUTING.
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Week 7 - Monday CS 121.
Presentation transcript:

Java for Beginners University Greenwich Computing At School DASCO Chris Coetzee

What do you learn last time? Wordle.org

Levels of Java coding 1: Syntax, laws, variables, output 2: Input, calculations, String manipulation 3: Selection (IF-ELSE) 4: Iteration/Loops (FOR/WHILE) 5: Complex algorithms 6: Arrays 7: File management 8: Methods 9: Objects and classes 10: Graphical user interface elements

Condition is a logic check something OPERATOR something Example: if(condition) Condition is a logic check something OPERATOR something Example: if(num == 3)

Logic operators in Java Function Example = = equals (int, double, char, boolean) if(num==3) .equals() equals (String) if(name.equals(“Chris”) ) > greater than if(num>20) < less than if(num<15) >= greater than or equal to if(age>=18) <= less than or equal to if(age<=12) != not equal to if(married!=true) Warning! = does not mean ==

AND/OR AND in Java: && OR in Java: || Used between conditions if(num>3&&<12)  if(num>3)&&(num<12)

Types of iteration (loops) Fixed number of times FOR loop Unspecified number of times WHILE loop

Can you predict the output?

for(counter; condition; change) A logic condition (like in IF) that has to be true for the loop to continue. Something Operator Something (usually involving the counter variable) A simple variable (usually an int) that allows the loop to ‘step through’ Normally called “i” for(counter; condition; change) What should happen to the counter variable value at the end of the loop Usually i++ or i--

Typical example (FOR loop) Create int called i Set i to 0 Continue while i is less than 3 At end of for loop, increase i by 1 for(int i = 0; i<3; i++) { System.out.println(“X”); } Output X

Another example (FOR loop) Create int called i Set i to 0 Continue while i is less than 5 At end of for loop, increase i by 1 for(int i = 0; i<5; i++) { System.out.println(i); } Output 1 2 3 4

Predict the outcome (FOR loop) What is the counter and starting value? What is the condition? What change happens? for(int j = 2; j<10; j=j+2) { System.out.println(j); } ? Output 2 4 6 8

Students struggle with… EVERYTHING ABOUT LOOPS Loops are an abstract construct. Lower ability students will need a LOT of simple practice. Most common mistake: for(int i = 0; i<5; i++);

Can you spot the mistake? FOR example Can you spot the mistake? Enter your favourite word > Cheese Here is Cheese 3 times! That’s all folks! Output

FOR with .charAt(x) s p e c t r u m ? Output

Detour: random numbers It can be very useful to make a random number in program. Java has a many ways to do this. Most common way is Math.random() Note: This is NOT an examinable bit, but it does teach logical thinking which IS examinable.

Making random numbers Math.random() generates a random double number between 0 and 1. e.g. 0.34212… or 0.93813 To make random int numbers between say 1 and 10 (both included), we need to use a bit of maths.

Useful formula: Min+(int)(Math.random()*((Max - Min) + 1)) Write down the minimum number and maximum number you need, and use the formula! So let’s make numbers between 1 and 10: 1 +(int)(Math.random()*((10 - 1) + 1))

FOR with random ints (A) ? 17 Output

FOR with random ints (B) ? 19 7 12 Output

Example task (advanced) Write a java program that will generate a random letter of the alphabet 5 times. Example output: g u l x e ?