Tuesday 22 December 2015

round() Method Pada Java - round() Method - Java NetBeans

Method round mengembalikan nilai long atau int terdekat, seperti yang diberikan oleh method tipe kembali.

Syntax :

Method ini menggunakan syntax berikut
long round(double d)
int round(float f)

Parameter

  • d - Sebuah primitif tipe data ganda atau mengapung
  • f - Sebuah float tipe data primitif

Return Value

  • Metode ini mengembalikan nilai long atau int terdekat, seperti yang ditunjukkan oleh metode tipe kembali untuk argumen.

Contoh :

Bukalah NetBeans kalian buatlah class bernama Test lalu tuliskan kode berikut
public class Test{ 

   public static void main(String args[]){
      double d = 100.675;
      double e = 100.500;
      float f = 100;
      float g = 90f;

      System.out.println(Math.round(d));
      System.out.println(Math.round(e)); 
      System.out.println(Math.round(f)); 
      System.out.println(Math.round(g)); 
   }
}
Berikut adalah hasil dari kode diatas
101
101
100
90

0 comments:

Post a Comment

luvne.com ayeey.com cicicookies.com mbepp.com kumpulanrumusnya.comnya.com tipscantiknya.com