Computer Science 15-100 (Sections S-V), Fall 2008
Homework 4
Due: Thu 25-Sep-2008 at 11:59pm (email copy) and at Friday's
class/recitation
(identical physical copy)
(no late submissions accepted).
Read these instructions first!
1 class Foo { 2 public static void main(String[] args) { 3 int x = 2, y = 12; 4 while (y-x > y/x) { 5 x+=7; 6 y+=3; 7 System.out.println(x + "," + y); 8 } 9 System.out.println(x + "," + y); 10 } 11 }
1 class Foo { 2 public static void main(String[] args) { 3 int x = 2, y; 4 for (y=(int)Math.pow(2,6); y >= x*x; x+=x) { 5 if (x % 4 > 0) 6 y++; 7 else 8 y += x; 9 System.out.println(x + "," + y); 10 } 11 System.out.println(x + "," + y); 12 } 13 }
1 class Foo {
2 public static int ack(int y, int z, int x) { // notice confusing parameter order!
3 x -= y + z;
4 z += y - x;
5 System.out.println(x + "," + y + "," + z);
6 return z % (x+2*y);
7 }
8
9 public static void main(String[] args) {
10 int x=2, y=3, z=2*y-1;
11 for (int w=1-ack(1,2,3); w+x+y+z<11; w++) {
12 x = ack(x, y, z);
13 System.out.println(w + "," + x + "," + y + "," + z);
14 }
15 }
16 }
Carpe diem!