Lesson 18 of 34

Methods: மீண்டும் பயன்படுத்தக்கூடிய codeMethods: Reusable Code

9 min 25 XP

Method என்பது பெயர் கொண்ட ஒரு code தொகுப்பு. ஒருமுறை எழுதி பலமுறை அழைக்கலாம். இப்போதைக்கு main()-க்கு அருகில் static methods எழுதுவோம். Parameters மூலம் மதிப்புகளை உள்ளே அனுப்பலாம்.

A method is a named block of code: write it once, call it many times. For now we'll write static methods next to main(). Parameters pass values in.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

void என்றால் அந்த method எதையும் திருப்பித் தராது (return இல்லை). அடுத்த பாடத்தில் மதிப்பைத் திருப்பித் தரும் methods பார்ப்போம்.

void means the method doesn't give back a value. Next lesson: methods that return values.

Challenge

+25 XP

printBox(String text) என்ற method எழுதுங்கள். அது text-ஐ இப்படி print செய்ய வேண்டும்: [ text ] main()-ல் input-லிருந்து ஒரு வரியைப் படித்து printBox-ஐ அழையுங்கள். Input: Hello Output: [ Hello ]

Write a method printBox(String text) that prints: [ text ] In main(), read a line of input and call printBox with it. Input: Hello Output: [ Hello ]

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.