Untuk membuat kelas pada project dengan Nama Februari_11:
Klik kanan mouse, klik new ada beberapa pilihan dan klik Java Class.
Sesudah
itu beri nama “Increment_Coba” (sesuka kalian beri nama apa)
Sesudah itu beri nama “ArithmeticDemo” (sesuka kalian beri nama apa)
contoh programnya:
public class ArithmeicDemo {
public static void main(String[] args) {
//beberapa angka
int i = 37;
int j = 42;
double x = 27.475;
double y = 7.22;
System.out.println("Nilai Variabel...");
System.out.println("Nilai Variabel...");
System.out.println(" i = " + i);
System.out.println(" j = " + j);
System.out.println(" x = " + x);
System.out.println(" y = " + y);
System.out.println("Penjumlahan...")
System.out.println(" i + j = " + (i + j ));
System.out.println(" x + y = " + (x + y));
//Pengurangan angka
System.out.println("Pengurangan...);
System.out.println("i - j = " + (i - j));
System.out.println("x - y = " + (x - y));
//Pengalian angka
System.out.println("Pengalian..."); System.out.println(" i * j = " + (i*j)); System.out.println(" x * y = " + (x*y));
System.out.println(" j = " + j);
System.out.println(" x = " + x);
System.out.println(" y = " + y);
System.out.println("Penjumlahan...")
System.out.println(" i + j = " + (i + j ));
System.out.println(" x + y = " + (x + y));
//Pengurangan angka
System.out.println("Pengurangan...);
System.out.println("i - j = " + (i - j));
System.out.println("x - y = " + (x - y));
//Pengalian angka
System.out.println("Pengalian..."); System.out.println(" i * j = " + (i*j)); System.out.println(" x * y = " + (x*y));
//pembagian angka
System.out.println("pembagian..."); System.out.println(" i / j = " + (i/j)); System.out.println(" x / y = " + (x/y));
//perhitungan modulus (sisa pembagian)
System.out.println("perhitungan modulus...");
System.out.println(" i % j = " + (i%j));
System.out.println(" x % y = " + (x%y));
//perhitungan kombinasi Variabel
System.out.println("perhitungan Variabel"); System.out.println(" j + y = " + (j+y)); System.out.println(" i + x = " + (i+x));
}
}
//perhitungan kombinasi Variabel
System.out.println("perhitungan Variabel"); System.out.println(" j + y = " + (j+y)); System.out.println(" i + x = " + (i+x));
}
}
contoh programnya;
public class Operator_logika {
public static void main(String[]args) {
int i = 0;
int j = 10;
boolean test= false;
//contoh &&
test=(i>10) && (j++>9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
//contoh &
test=(i>10) & (j++>9);
System.out.println(j);
System.out.println(test);
//contoh ||
test=(i<10) || (j++>9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
//contoh |
test=(i>10) | (j++>9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
blooean val2 = true;
System.out.println(val1 ^ val2);
val1 = false; val2 = true;
System.out.println(val1 ^ val2);
val1 = false; val2 = false; System.out.println(val1 ^ val2);
val1 = true; val2 = false; System.out.println(val1 ^ val2);
//ini untuk testNOT
blooean val3 = true;
blooean val4 = false;val1 = false; val2 = true;
System.out.println(val1 ^ val2);
val1 = false; val2 = false; System.out.println(val1 ^ val2);
val1 = true; val2 = false; System.out.println(val1 ^ val2);
//ini untuk testNOT
blooean val3 = true;
System.out.println(!val3); System.out.println(!val4); }
}
public class RelationalDemo {
public static void main (String[] args) {
//beberapa angka
int i = 37;
int j = 42;
int k = 42;
System.out.println(Nilai Variabel…);
System.out.println(“ i = “ + i);
System.out.println(“ j = “ + j);
System.out.println(“ k = “ + k);
//lebih besar dari
System.out.println(lebih besar…);
System.out.println(" i > j = " + (i>j));//false
System.out.println(" j > i = " + (j>i));//false System.out.println(" k > j = " + (k>j));//falseSystem.out.println(“ k = “ + k);
//lebih besar dari
System.out.println(lebih besar…);
System.out.println(" i > j = " + (i>j));//false
//lebih besar atau sama dengan
System.out.println(Lebih besar atau sama dengan…);
System.out.println(" i >= j = " + (i>=j));//false;
System.out.println(" j >= i = " + (j>=i));//true; System.out.println(" k >= j = " + (k>=j));//true;
//lebih kecil
System.out.println(Lebih kecil…);
System.out.println(" i < j = " + (i<j));//true
System.out.println(Lebih besar atau sama dengan…);
System.out.println(" i >= j = " + (i>=j));//false;
System.out.println(" j >= i = " + (j>=i));//true; System.out.println(" k >= j = " + (k>=j));//true;
//lebih kecil
System.out.println(Lebih kecil…);
System.out.println(" i < j = " + (i<j));//true
System.out.println(" j < i = " + (j<i));//false System.out.println(" k < j = " + (k<j));//false
System.out.println(" j <= i = " + (j<=i));//false; System.out.println(" k <= j = " + (k<=j));//true;
//sama dengan
System.out.println("sama dengan..."); System.out.println( i == j = " + (i==j));//false System.out.println( k == j = " + (k==j));//true
//tidak sama dengan
System.out.println("tidak sama dengan...");
System.out.println(" i != j =" + (i!=j));//true System.out.println(" k != j =" + (k!=j));//false
}
}
Tidak ada komentar:
Posting Komentar