← Όλα τα κεφάλαια
Κεφάλαιο 6

Μέθοδοι

Δηλώσεις, παράμετροι, return, overloading.

Δήλωση

static int add(int x, int y) { return x+y; }

Κλήση

add(2,3) // 5

Ασκήσεις

Δοκίμασέ τες — οι λύσεις είναι κρυμμένες μέχρι να τις ζητήσεις.

#1Μέθοδος add

Φτιάξε static int add(int,int) και τύπωσε add(2,3).

#2MCQ — return void

Τι επιστρέφει μια void μέθοδος;

#3add(5,7)

Φτιάξε static add και κάλεσε add(5,7).

#4square(5)

Γράψε static int square(int) και τύπωσε square(5).

#5fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#6add(11,16)

Φτιάξε static add και κάλεσε add(11,16).

#7square(8)

Γράψε static int square(int) και τύπωσε square(8).

#8fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#9add(2,8)

Φτιάξε static add και κάλεσε add(2,8).

#10square(11)

Γράψε static int square(int) και τύπωσε square(11).

#11fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#12add(8,17)

Φτιάξε static add και κάλεσε add(8,17).

#13square(4)

Γράψε static int square(int) και τύπωσε square(4).

#14fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#15add(14,9)

Φτιάξε static add και κάλεσε add(14,9).

#16square(7)

Γράψε static int square(int) και τύπωσε square(7).

#17fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#18add(5,1)

Φτιάξε static add και κάλεσε add(5,1).

#19square(10)

Γράψε static int square(int) και τύπωσε square(10).

#20fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#21add(11,10)

Φτιάξε static add και κάλεσε add(11,10).

#22square(3)

Γράψε static int square(int) και τύπωσε square(3).

#23fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#24add(2,2)

Φτιάξε static add και κάλεσε add(2,2).

#25square(6)

Γράψε static int square(int) και τύπωσε square(6).

#26fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#27add(8,11)

Φτιάξε static add και κάλεσε add(8,11).

#28square(9)

Γράψε static int square(int) και τύπωσε square(9).

#29fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#30add(14,3)

Φτιάξε static add και κάλεσε add(14,3).

#31square(2)

Γράψε static int square(int) και τύπωσε square(2).

#32fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#33add(5,12)

Φτιάξε static add και κάλεσε add(5,12).

#34square(5)

Γράψε static int square(int) και τύπωσε square(5).

#35fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#36add(11,4)

Φτιάξε static add και κάλεσε add(11,4).

#37square(8)

Γράψε static int square(int) και τύπωσε square(8).

#38fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#39add(2,13)

Φτιάξε static add και κάλεσε add(2,13).

#40square(11)

Γράψε static int square(int) και τύπωσε square(11).

#41fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#42add(8,5)

Φτιάξε static add και κάλεσε add(8,5).

#43square(4)

Γράψε static int square(int) και τύπωσε square(4).

#44fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#45add(14,14)

Φτιάξε static add και κάλεσε add(14,14).

#46square(7)

Γράψε static int square(int) και τύπωσε square(7).

#47fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#48add(5,6)

Φτιάξε static add και κάλεσε add(5,6).

#49square(10)

Γράψε static int square(int) και τύπωσε square(10).

#50fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#51add(11,15)

Φτιάξε static add και κάλεσε add(11,15).

#52square(3)

Γράψε static int square(int) και τύπωσε square(3).

#53fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#54add(2,7)

Φτιάξε static add και κάλεσε add(2,7).

#55square(6)

Γράψε static int square(int) και τύπωσε square(6).

#56fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#57add(8,16)

Φτιάξε static add και κάλεσε add(8,16).

#58square(9)

Γράψε static int square(int) και τύπωσε square(9).

#59fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#60add(14,8)

Φτιάξε static add και κάλεσε add(14,8).

#61square(2)

Γράψε static int square(int) και τύπωσε square(2).

#62fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#63add(5,17)

Φτιάξε static add και κάλεσε add(5,17).

#64square(5)

Γράψε static int square(int) και τύπωσε square(5).

#65fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#66add(11,9)

Φτιάξε static add και κάλεσε add(11,9).

#67square(8)

Γράψε static int square(int) και τύπωσε square(8).

#68fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#69add(2,1)

Φτιάξε static add και κάλεσε add(2,1).

#70square(11)

Γράψε static int square(int) και τύπωσε square(11).

#71fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#72add(8,10)

Φτιάξε static add και κάλεσε add(8,10).

#73square(4)

Γράψε static int square(int) και τύπωσε square(4).

#74fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#75add(14,2)

Φτιάξε static add και κάλεσε add(14,2).

#76square(7)

Γράψε static int square(int) και τύπωσε square(7).

#77fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#78add(5,11)

Φτιάξε static add και κάλεσε add(5,11).

#79square(10)

Γράψε static int square(int) και τύπωσε square(10).

#80fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#81add(11,3)

Φτιάξε static add και κάλεσε add(11,3).

#82square(3)

Γράψε static int square(int) και τύπωσε square(3).

#83fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#84add(2,12)

Φτιάξε static add και κάλεσε add(2,12).

#85square(6)

Γράψε static int square(int) και τύπωσε square(6).

#86fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#87add(8,4)

Φτιάξε static add και κάλεσε add(8,4).

#88square(9)

Γράψε static int square(int) και τύπωσε square(9).

#89fact(5) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(5).

#90add(14,13)

Φτιάξε static add και κάλεσε add(14,13).

#91square(2)

Γράψε static int square(int) και τύπωσε square(2).

#92fact(8) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(8).

#93add(5,5)

Φτιάξε static add και κάλεσε add(5,5).

#94square(5)

Γράψε static int square(int) και τύπωσε square(5).

#95fact(11) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(11).

#96add(11,14)

Φτιάξε static add και κάλεσε add(11,14).

#97square(8)

Γράψε static int square(int) και τύπωσε square(8).

#98fact(2) αναδρομικά

Αναδρομική static long fact(int) — τύπωσε fact(2).

#99add(2,6)

Φτιάξε static add και κάλεσε add(2,6).

#100square(11)

Γράψε static int square(int) και τύπωσε square(11).