Share knowledge�.

3/December/2007

return

Filed under: Java - Administrator @ 4:32 pm

+ digunakan untuk mengeluarkan hasil dari method, contoh:
. . .
int hitung(int a,int b){
    int c = a + b;
    return c;
}

+ Perhatikan, return mengeluarkan hasil dari perhitungan c, sehingga siapa saja yang memanggil method ini akan memperoleh hasil
perhitunganya.

+ Juga perhatikan, tentukan tipe data yang di-return-kan di sebelum nama method. Contoh di atas mendeklarasikan tipe keluaran method-nya
adalah int karena nilai yang di-return-kan adalah int. Berlaku sama untuk tipe data lain, namun jika tidak ada return; gunakan defenisi void, contoh:

    void cetak(int a,int b){
        int c = a + b;
        System.out.println("Hasil penjumlahan ="+c);
    }

2 Comments »

The URI to TrackBack this entry is: http://computerteach.blogsome.com/2007/12/03/return/trackback/

  1. apakah letak
    int hitung(int a,int b){
    int c = a + b;
    return c;
    boleh diletakkan belakangan? setelah void cetak?

    Comment by nicho herwanto — 11/December/2007 @ 10:54 am

  2. @herwanto
    Boleh tapi saat memanggilnya harus berurut.

    Comment by Mauladi — 22/January/2008 @ 5:06 am

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Alex King