New topic: Conditionals
Click on this label:
Classwork:
Flowcharts: write a short code fragment for each of the following flowcharts:
if and if/else
while and for loops
More on conditionals with the slides on this link:
Assignments:
- Write a more general and robust version of ComplexRootsQuad.java that prints the roots of the polynomial ax^2 + bx + c, prints real and complex solutions.
- What (if anything) is wrong with each of the following statements?
if (a > b) then c = 0;
if a > b { c = 0; }
if (a > b) c = 0;
if (a > b) c = 0 else b = 0; - Write a code fragment that prints true if the double variables x and y are both strictly between 0 and 1 and false otherwise.
- Write a program AllEqual_YI.java that takes three integer command-line arguments and prints equal if all three are equal, and not equal otherwise.
- Rewrite TenHellos.java to make a program ManyHellos_YI.java that prompts the user for the consecutive lines to print… You may assume that the argument is less than 1000. Hint: consider using i % 10 and i % 100 to determine whether to use “st”, “nd”, “rd”, or “th” for printing the ith Hello.Example output:
* Starting number? 4
* Ending number? 8* 4th Hello
* 5th Hello
* 6th Hello
* 7th Hello
* 8th Hello - What is the value of m and n after executing the following code?
int n = 123456789; int m = 0; while (n != 0) { m = (10 * m) + (n % 10); n = n / 10; }
- What does the following code print out?
int f = 0, g = 1; for (int i = 0; i <= 15; i++) { System.out.println(f); f = f + g; g = f - g; }
A site to check your understanding: