Lab 01: Setting up your computer
Instructions: https://fa22.datastructur.es/materials/lab/lab01/
Solution: https://github.com/tomthestrom/cs61b/tree/master/lab01
A lot of reading about setting everything up, then you're encouraged to implement the int nextNumber
method in Collatz
and make bool isLeapYear
return true, optionally implementing it.
Easy tasks to make sure everything's working as it's supposed to.
Solutions:
public static int nextNumber(int n) {
if (n == 1) {
return 1;
} else if (n % 2 == 1) {
return (3 * n) + 1;
} else {
return n / 2;
}
}
public static boolean isLeapYear(int year) {
// Optional
return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
}
Last updated