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