Created
January 12, 2012 07:19
-
-
Save mluukkai/1599216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Lapikayja{ | |
void operoi(int luku); | |
int tulos(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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