Skip to content

Instantly share code, notes, and snippets.

@mluukkai
Created January 12, 2012 07:19
Show Gist options
  • Save mluukkai/1599216 to your computer and use it in GitHub Desktop.
Save mluukkai/1599216 to your computer and use it in GitHub Desktop.
interface Lapikayja{
void operoi(int luku);
int tulos();
}
public class Main {
public static void main(String[] args) {
int[] luvut = {1, 2, 3, 4, 5, 6};
int s = summa(luvut, new Lapikayja() {
int summa = 0;
@Override
public void operoi(int luku) {
summa += luku;
}
@Override
public int tulos() {
return summa;
}
});
System.out.println( s );
}
private static int summa(int[] luvut, Lapikayja lapikayja) {
for (int luku : luvut) {
lapikayja.operoi(luku);
}
return lapikayja.tulos();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment