Week 3 - Friday.  What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Intro to Scala Lists. Scala Lists are always immutable. This means that a list in Scala, once created, will remain the same.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Chapter 3A Review boolean fun = true; if(fun) System.out.print(“yeah!”);
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
1 Working with String Duo Wei CS110A_ Empty Strings An empty string has no characters; its length is 0. Not to be confused with an uninitialized.
Java Programming Strings Chapter 7.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Chapter 10 Review. Write a method that returns true is s1 and s2 end with the same character; otherwise return false. Sample Answer: public boolean lastChar(String.
CS0007: Introduction to Computer Programming
Lecture 2 Introduction to C Programming
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Programming 2 CS112- Lab 2 Java
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
11-Jun-15 Just Enough Java. 2 What is Java? Java is a programming language: a language that you can learn to write, and the computer can be made to understand.
Introduction to Computers and Programming Lecture 7:
COMP 14 Introduction to Programming Miguel A. Otaduy May 18, 2004.
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 30, 2005.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
The switch Statement, DecimalFormat, and Introduction to Looping
Week 3 - Wednesday.  What did we talk about last time?  Math methods  Lab 2.
Week 2 - Friday.  What did we talk about last time?  Using Scanner to get input  Basic math operations.
Week 4 - Monday.  What did we talk about last time?  Wrapper classes  if statements.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
CS177 Week2: Recitation Primitive data types and Strings with code examples.
Introduction to Java Java Translation Program Structure
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Operations on Strings. 8/8/2005 Copyright 2006, by the authors of these slides, and Ateneo de Manila University. All rights reserved L: String Manipulation.
Computing with C# and the.NET Framework Chapter 3 Software Engineering with Control Structures.
CHAPTER 8 File Input Output Part 1: String. The String Class  Constructing a String: String message = "Welcome to Java“; String message = new String("Welcome.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
ICT Introduction to Programming Chapter 4 – Control Structures I.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
A: A: double “4” A: “34” 4.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Java String Methods - Codehs
Week 3 - Monday.  What did we talk about last time?  Using Scanner to get input  Basic math operations  Lab 2.
Week 2 - Wednesday CS 121.
Week 3 - Wednesday CS 121.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
CS0007: Introduction to Computer Programming
INC 161 , CPE 100 Computer Programming
String class.
Week 4 - Monday CS 121.
C# and the .NET Framework
Primitive Types Vs. Reference Types, Strings, Enumerations
An Introduction to Java – Part I
Chapter 2.
Advanced Programming Behnam Hatami Fall 2017.
Review Operation Bingo
Chapter 7: Strings and Characters
Introduction to Python
An Introduction to Java – Part I, language basics
Java so far Week 7.
The keyboard is the standard input device.
CS2011 Introduction to Programming I Strings
Unit 3: Variables in Java
Switch, Strings, and ArrayLists in Java
Introduction to java Part I By Shenglan Zhang.
More on iterations using
Week 3 - Friday COMP 1600.
Unit-2 Objects and Classes
Presentation transcript:

Week 3 - Friday

 What did we talk about last time?  Operations on boolean values  !, &&, ||  Operations on char values  +, -  Operations on String values  Concatenate (+)  equals()  compareTo()  length()  charAt()  substring()

 For Project 1, the easiest way to print out data with 2 decimal places is put "%.2f" in the formatting string for System.out.format()  If you want, you can include other things in the formatting string double x = ; System.out.format("%.2f", x); //prints 5.75 double x = ; System.out.format("%.2f", x); //prints 5.75 System.out.format("Total = $%.2f", ); //prints Total = $15.78

 Write a program that reads in an alphabetic character and tells you what position in the alphabet it has  Write a program that reads three String values and prints them out in reverse order  Write a program that reads in an int value and says how many digits it contains

 So far we have only considered Java programs that do one thing after another, in sequence  Our programs have not had the ability to choose between different possibilities  Now, they will!

 The if -statement:  x is small will only print out if x is less than 5  In this case, we know that it is, but x could come from user input or a file or elsewhere int x = 4; if( x < 5 ) System.out.println("x is small!"); int x = 4; if( x < 5 ) System.out.println("x is small!");

The if part Any boolean expression Any single executable statement if( condition ) statement;

 A very natural if-then sort of relationship  If the condition is true, then do something  For example:  If I win a million dollars,  Then I’ll yodel like an insane Swiss monkey

 More on if statements  else statements  Conditions

 Read Chapter 4 of the textbook  Keep working on Project 1  Due next Friday