10/9/07 ______ ------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||

Slides:



Advertisements
Similar presentations
2/7/2008. >>> Overview * boolean * while * random * tuples.
Advertisements

Nested for loops Cont’d. 2 Drawing complex figures Use nested for loops to produce the following output. Why draw ASCII art? –Real graphics require a.
Expressions, variables, and for loops (oh my!) spam, spam, spam, spam
Copyright 2008 by Pearson Education 1 Class constants and scope reading: 2.4 self-check: 28 exercises: 11 videos: Ch. 2 #5.
Week 2 ______ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
Building Java Programs
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
11/27/07. >>> Overview * objects * class * self * in-object methods * nice printing * privacy * property * static vs. dynamic * inheritance.
Building Java Programs Chapter 2 Primitive Data and Definite Loops.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Java Methods. Topics  Declaring fields vs. local variables  Primitive data types  Strings  Compound Assignment  Conversions from one value to another.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Week 4. >>> Overview * if else * returns * input.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Chapter 2: Java Fundamentals
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-3: Loop Figures and Constants reading: self-checks: 27 exercises:
Unit 2 Expressions and variables; for loops Special thanks to Roy McElmurry, John Kurkowski, Scott Shawcroft, Ryan Tucker, Paul Beck for their work. Except.
1 BUILDING JAVA PROGRAMS CHAPTER 2 Pseudocode and Scope.
Week 1 basic Python programs, defining functions Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where.
1 Building Java Programs Chapter 3: Introduction to Parameters and Objects These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 2 expressions, variables, for loops Special thanks to Scott Shawcroft, Ryan Tucker, Paul Beck, Hélène Martin, Kim Todd, John Kurkowski, and Marty.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 4: Loop Figures and Constants reading:
Building Java Programs Chapter 2 Primitive Data and Definite Loops.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
1/10/2008. >>> About Us Paul Beck * Third quarter TA * Computer Engineering * Ryan Tucker * Second quarter TA * Computer.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
Topic 6 loops, figures, constants Based on slides bu Marty Stepp and Stuart Reges from "Complexity has and will maintain.
Copyright 2008 by Pearson Education 1 Nested loops reading: 2.3 self-check: exercises: videos: Ch. 2 #4.
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.
8/2/07. >>> About Me Scott Shawcroft * Junior * Computer Engineering * Third Quarter TA * Creative Commons Intern * Small-time Open Source Developer
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 2: Primitive Data and Definite Loops.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
10/30/07. >>> Overview * boolean * randomness * while * tuples.
10/30/07.
10/16/07.
10/9/07 ______ < Moo? > \ ^__^ \ (oo)\_______ (__)\ )\/\
Lecture 5: Some more Java!
Building Java Programs
CSCI 161 – Introduction to Programming I William Killian
OUTPUT STATEMENTS GC 201.
An Introduction to Java – Part I, language basics
CSc 110, Autumn 2016 Lecture 5: Loop Figures and Constants
expressions, variables, for loops
expressions, variables, for loops
Building Java Programs
Chapter 2: Java Fundamentals
CSc 110, Spring 2018 Lecture 7: input and Constants
Building Java Programs
Lecture 5: For Loops Building Java Programs: A Back to Basics Approach
Variables, Types, Operations on Numbers
CSc 110, Spring 2018 Lecture 5: Loop Figures and Constants
Topic 6 loops, figures, constants
Building Java Programs
Building Java Programs
Building Java Programs
Winter 2019 CMPE212 4/7/2019 CMPE212 – Reminders
Building Java Programs
Suggested self-checks:
Building Java Programs
Drawing complex figures
Unit 3: Variables in Java
Building Java Programs
Building Java Programs
JAVA. Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of platforms, such.
Chapter 2 Lecture 2-3: Loop Figures and Constants reading:
Presentation transcript:

10/9/07 ______ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||

>>> Reminders * Code feedback for Pythony things only. * NOT logic errors that will also be in Java code. _________________________________ / Could someone help me reboot my \ \ spaceship? / \ ^__^ \ (==)\_______ (__)\ )\/\ ||----w | || ||

>>> Last Time * print * escape sequences * functions >>> print "a string" a string >>> print 'a string' a string >>> print #a string# >>> print $a string$ File " ", line 1 print $a string$ ^ SyntaxError: invalid syntax A whaa? function – a subroutine independent of other code. method – a subroutine associated with a class (think public class...) or object.

>>> Overview * types * variables * for loops * 1337 ASCII art _________ \ ^__^ \ (**)\_______ (__)\ )\/\ U ||----w | || ||

int float str bool >>> Types Python cares very little about types. In Java, one must declare a variable with a particular type and maintain that type throughout the existance of that variable. In other words, ints can be only stored in places designated for ints, same for doubles etc. This is not the case in Python. Python does not care about types until the very last moment. This last moment is when values are used in certain ways, such as concatination. int double String char boolean Java python “wow” 'w' True >>> "Suppose " " swallows carry it together." Traceback (most recent call last): File " ", line 1, in TypeError: cannot concatenate 'str' and 'int' objects >>> "Suppose " + str(2) + " swallows carry it together." 'Suppose 2 swallows carry it together.'

>>> Expressions 4 * 3/ * 2 ( )/2 26 % 10 % 4 * 3 9/4 * 2.0 – 5/4 (5 * 7.0/ )/5 * 2 3 * * 3 12/7 * 4.4 * 2/4 177 % 100 % 10/2 "hello 34 " + 2 * 4 9/ /3 – 3.0/2 "2 + 2 " % 100/ " 2 + 2" 27/2/2.0 * ( ) – 8/3 Expressions.java 4 * 3/ * 2 ( )/2 26 % 10 % 4 * 3 9/4 * /4 (5 * 7.0/ )/5 * 2 3 * * 3 12/7 * 4.4 * 2/4 177 % 100 % 10/2 "hello 34 " + str(2 * 4)‏ 9/ / /2 "2 + 2 " + str(3) + str(4)‏ 813 % 100/ str(3 + 4) + " 2 + 2" 27/2/2.0 * ( ) – 8/3 “hello”*3+”wow” “hello”*2+” world” expressions.py

... int x = 2; x++; System.out.println(x); x = x * 8; System.out.println(x); double d = 3.0; d /= 2; System.out.println(d); >>> Variables As said earlier, Python cares less about types. This is the case when creating a variable. Unlike Java, Python does not care what type is in what variable. As a result, in Python to creating a variable is like Java without the type. Variables.java x = 2 x += 1 print x x = x * 8 print x d = 3.0 d /= 2 print d s = “wow” print s expressions.py

>>> Constants Continuing Python's free spirited ways, it has much less restrictions than Java. Because of this, constants are possible but not in a commonly used manner. Instead, we'll designate constants in Python solely by the variable capitalization. SIZE = 2 x = 10 * SIZE print x constants.py

>>> Python's For for i in range(4): # (end)‏ print i for i in range(1,4): # (start,end)‏ print i for i in range(2,8,2): # (start,end,step_size)‏ print i # for in : # for.py Unlike Java's for loop, Python's for loop loops over elements in a sequence. To loop over a certain sequence of integers use the range() function. A whaa? sequence – a series of elements. Ex: [1,2,3,4,5] is a sequence produced by range(1,6)‏ Ex: [“milk”,”juice”,”bread”] is my grocery list >>> range(4)‏ [0, 1, 2, 3] >>> range(1,4)‏ [1, 2, 3] >>> range(2,8,2)‏ [2, 4, 6] >>> range(8,0,-2)‏ [8, 6, 4, 2]

>>> Mirror #================# | <><> | | <>....<> | | <> <> | |<> <>| | <> <> | | <>....<> | | <><> | #================# yossarian ~ $ python mirror.py // Marty Stepp, CSE 142, Autumn 2007 // This program prints an ASCII text figure that // looks like a mirror. // This version uses a class constant to make the figure resizable. public class Mirror2 { public static final int SIZE = 4; // constant to change the figure size public static void main(String[] args) { line(); topHalf(); bottomHalf(); line(); } // Prints the top half of the rounded mirror. public static void topHalf() { for (int line = 1; line <= SIZE; line++) { // pipe System.out.print("|"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // <> System.out.print("<>"); // dots. for (int j = 1; j <= 4 * line - 4; j++) { System.out.print("."); } // <> System.out.print("<>"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // pipe System.out.println("|"); } // Prints the bottom half of the rounded mirror. public static void bottomHalf() { for (int line = SIZE; line >= 1; line--) { // pipe System.out.print("|"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // <> System.out.print("<>"); // dots. for (int j = 1; j <= 4 * line - 4; j++) { System.out.print("."); } // <> System.out.print("<>"); // spaces for (int j = 1; j <= -2 * line + (2 * SIZE); j++) { System.out.print(" "); } // pipe System.out.println("|"); } // Prints the #==# line at the top and bottom of the mirror. public static void line() { System.out.print("#"); for (int j = 1; j <= 4 * SIZE; j++) { System.out.print("="); } System.out.println("#"); }

>>> Castle Arggh _ _ _ _ _ _ _ _ | |_| |_| |_| | \ / \___________/ \___________/ | | __ __ __ __ __ __ __ __ __ __ __ | | | |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| | | | | | | | ______ | | | | /||||||\ | | | | /||||||||\ | | | | |||||||||||| | | |_________|______________________||||||||||||______________________|_________| yossarian ~ $ python arggh.py

Except where otherwise noted, this work is licensed under © 2007 Scott Shawcroft, Some Rights Reserved Python® and the Python logo are either a registered trademark or trademark of the Python Software Foundation. Java™ is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other countries.