






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







โ assignment 2 is graded โ assignment 3 is due 11/ โ midterm is scheduled for 10/ โ omet survey is scheduled for 11/
boolean compareNumbers(int x, int y) { if(x<y) return true; else return false; }
Fibonacci function โ fib(0) = 0 โ fib(1) = 1 โ fib(n) = fib(n-1) + fib(n-2)
public class Fibonacci { public static void main(String[] args) { int N = 10; for (int i = 1; i <= N; i++) System.out.println(i +":"+ fib(i)); } public static long fib(int n) { if (n <= 1) return n; else return fib(n-1) + fib(n-2); } }
class Basic_Array { public static void main (String[] args) { int LIMIT = 15; int INCREMENT = 10; int[] list = new int[LIMIT]; for (int index = 0 ; index < LIMIT; index++) list[index] = index * INCREMENT; list[5] = 999 ; for (int index = 0; index < LIMIT; index++) System.out.print (list[index] + " "); System.out.println (); } } 0 10 20 30 40 999 60 70 80 90 100 110 120 130 140
class Children { public static void main (String[] args) { String[] name_list = {"Joshua", "Bethany", "Megan", "Eric"}; for (int name = 0 ; name < name_list.length; name++) System.out.println (name_list[name]); } }
public static double mean(double[] a ) { double sum = 0.0; for (int i = 0; i< a .length; i++) sum = sum + a [i]; return sum / a .length; } public static void main(String[] args){ ... double average = mean(a); ... }
we are now in position to decipher it: public static void main(String[] args) { for (int i = 0; i < args.length; i++) System.out.println(args[i]); } run it on: 10 20 30 Hello 0.50000 "Hi"