Академический Документы
Профессиональный Документы
Культура Документы
Review #1 - #4
Outline
Introduction to Java
Class, Object, Method, Variable, Algorithm
Data Types, Operators, and Expression
Constant, Conversion, String
Rectangle gambarKotak;
Rectangle drawKotak;
x Math.sqrt(x)
b b 2 4ac
b b 2 4ac
2a
11/02/21 Algoritma & Pemrograman 42
Package / Library: Math [4]
Math.sqrt( x) square root of x ( x 0)
Math.pow( x, y ) x y ( x 0, or x 0 and y 0,
or x 0 and y is an integer)
Math.sin( x) sine of x ( x in radians)
Math.cos( x) cosine of x ( x in radians)
Math.tan( x) tangent of x ( x in radians)
Math.asin( x) (arc sine) sin -1 x [ 2, 2 ], x [ 1,1]
Math.acos( x) (arc cosine) cos -1 x [0, ], x [1,1]
Math.atan( x) (arc tangent) tan -1 x [ 2, 2 ]
Math.atan2(
11/02/21
y , x) (arc tangent) tan -1
Algoritma & Pemrograman
( y x) [ , ], x may be430
Package / Library: Math [5]
Math.round( x) the closest integer to x (as a long)
Math.ceil( x) smallest integer x (as a double)
Math.floor( x) largest integer x (as a double)
Math.abs( x) absolute value x
Math.toDegrees( x) tangent of x ( x in radians)
Math.toRadians(x) converts x degrees to radians
(i.e. returns x 180)
Math.log( x) (natural log) ln( x), x 0
Math.exp( x) ex
11/02/21 Algoritma & Pemrograman 44
Java: Tipe Data
Terdapat dua jenis tipe data:
Primitive types: numeric type, boolean type
substr(7,5)
11/02/21 Algoritma & Pemrograman 48
String: concatenate
Menggabung (concatenate) 2 string dengan operator +
String fname = "Bambang";
String lname = "Wijanarko";
String name = fname + lname;
Hasilnya? name = "BambangWijanarko"
Jika ingin name = "Bambang Wijanarko", maka
String name = fname + " " + lname;
String juga melakukan konversi dari bilangan ke string
secara otomatis
String id = "Agent" + 7; // Hasilnya "Agent7"
double double
int i = (int)12.5f;
System.out.println("Nilai (int)12.5f: " + i);
float f = i;
System.out.println("Float widening f: " + f);
Output:
Nilai (int)12.5f: 12
Float widening f: 12.0