Conditionals: Ex 1-4

 

Classwork:

  1. Write a program YI_FivePerLine.java that, using one for loop and one if statement, prints the integers from 1000 to 2000 with five integers per line. Hint: use the % operator.

  2. Write a program YI_FunctionGrowth.java that prints a table of the values of ln n, n, n ln n, n^2, n^3, and 2^n for n = 16, 32, 64, …, 2048. Use tabs (‘\t’ characters) to line up columns.

Homework:

  1. 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;
}

  1. 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;
}