Tuesday, April 15, 2014

Homework 8

page 427, problem 9

1
2
3
4
5
6
7
8
static public boolean allPositive(double[] arr)
{
    for (int i = 0; i < arr.length; i++) {
       if (i < 0)
          return false;
    }
    return true;
}

page 427, problem 10

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
public boolean equals(Students that)
{
    if (this.studentIds.length != that.studentIds.length)
        return false;

    for (int i = 0; i < this.students.length;i++) {
        if (this.studentsIds[i] != that.students[i])
            return false;
    }
   return true;
}

}

page 468, problem 11

i = 5, factorial = 5

This happens cause the loop never runs the factorial *=

page 468, problem 12

1
2
for (entry = ""; entry = stdIn.nextLine(); !entry.equals("q") )
  System.out.println("Enter 'q' to quit: ");

No comments:

Post a Comment