Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 Week 3 - Friday

2  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()

3

4

5  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 = 5.74961; System.out.format("%.2f", x); //prints 5.75 double x = 5.74961; System.out.format("%.2f", x); //prints 5.75 System.out.format("Total = $%.2f", 15.7777); //prints Total = $15.78

6  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

7

8  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!

9  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!");

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

11  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

12

13

14  More on if statements  else statements  Conditions

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


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

Similar presentations


Ads by Google