Masukan program di bawah ini. silakan anda cek.
public class kelasmath{
public static void main (String[]args){
//method pembulatan abs() dan ceil() floor() round()
int a=7;
int b=-7;
System.out.println("nilai a "+a);
System.out.println("nilai b "+b);
System.out.println("nilai absolut a="+Math.abs(a));
System.out.println("nilai absolut a="+Math.abs(a));
//ceil() mengembalikan nilai integer terkecil dan tidak lebih kecil dari argumen
//floor() mengembalikan niali integer terbesar dan tidak lebih besar dari argumen
double c=7.3;
double d=-7.3;
System.out.println("nilai c "+c);
System.out.println("nilai d "+d);
System.out.println("nilai ceil c="+Math.ceil(c));
System.out.println("nilai ceil d="+Math.ceil(d));
System.out.println("nilai floor c="+Math.floor(d));
System.out.println("nilai floor d="+Math.floor(d));
//round
double e=7.39;
double f=-7.5;
System.out.println("nilai e "+e);
System.out.println("nilai f "+f);
System.out.println("nilai round a="+Math.round(e));
System.out.println("nilai round a="+Math.round(f));
}
}
public static void main (String[]args){
//method pembulatan abs() dan ceil() floor() round()
int a=7;
int b=-7;
System.out.println("nilai a "+a);
System.out.println("nilai b "+b);
System.out.println("nilai absolut a="+Math.abs(a));
System.out.println("nilai absolut a="+Math.abs(a));
//ceil() mengembalikan nilai integer terkecil dan tidak lebih kecil dari argumen
//floor() mengembalikan niali integer terbesar dan tidak lebih besar dari argumen
double c=7.3;
double d=-7.3;
System.out.println("nilai c "+c);
System.out.println("nilai d "+d);
System.out.println("nilai ceil c="+Math.ceil(c));
System.out.println("nilai ceil d="+Math.ceil(d));
System.out.println("nilai floor c="+Math.floor(d));
System.out.println("nilai floor d="+Math.floor(d));
//round
double e=7.39;
double f=-7.5;
System.out.println("nilai e "+e);
System.out.println("nilai f "+f);
System.out.println("nilai round a="+Math.round(e));
System.out.println("nilai round a="+Math.round(f));
}
}
hasil outputnya:
Tidak ada komentar:
Posting Komentar