fundamental

1.Tujuan
● Mengidentifikasi bagian dasar dari program java
● Membedakan mana yang termasuk ke dalam java literals, tipe data dasar, tipe variabel, pengidentifikasian dan operator.
● Mengembangkan program java sederhana menggunakan konsep pembelajaran pada bab ini.
● Menganalisa program java pertama saya
2. Percobaan
Percobaan 1 : Program Java Pertama
public class Hello {
public Hello() {
}
public static void main(String[] args) {
System.out.println(“Hello world!”);
}
}
Output Percobaan 1 :
Distributed by Meruvian Education
Percobaan 2 : Deklarasi dan Inisialisasi Variabel:
public class VariableSamples {
public VariableSamples() {
}
public static void main( String[] args ){
boolean result;
char option;
option = ‘C’;
double grade = 0.0;
}
}
Output Percobaan 2 :
Percobaan 3 : Menampilkan Data Variabel
public class OutputVariable {
public OutputVariable() {
}
public static void main( String[] args ){
int value = 10;
char x;
x = ‘A’;
System.out.println( value );
System.out.println( “The value of x=” + x );
}
}
Distributed by Meruvian Education
Output Percobaan 3 :
Distributed by Meruvian Education
Percobaan 4 : Demo Operator Arithmetic
public class ArithmeticDemo {
public ArithmeticDemo() {
}
public static void main(String[] args){
int i = 37;
int j = 42;
double x = 27.475;
double y = 7.22;
System.out.println(“Variable values…”);
System.out.println(” i = ” + i);
System.out.println(” j = ” + j);
System.out.println(” x = ” + x);
System.out.println(” y = ” + y); //adding numbers
System.out.println(“Adding…”);
System.out.println(” i + j = ” + (i + j));
System.out.println(” x + y = ” + (x + y));
System.out.println(“Subtracting…”);
System.out.println(” i – j = ” + (i – j));
System.out.println(” x – y = ” + (x – y));
System.out.println(“Multiplying…”);
System.out.println(” i * j = ” + (i * j));
System.out.println(” x * y = ” + (x * y));
System.out.println(“Dividing…”);
System.out.println(” i / j = ” + (i / j));
System.out.println(” x / y = ” + (x / y));
System.out.println(“Computing the remainder…”);
System.out.println(” i % j = ” + (i % j));
System.out.println(” x % y = ” + (x % y));
System.out.println(“Mixing types…”);
System.out.println(” j + y = ” + (j + y));
System.out.println(” i * x = ” + (i * x));
}
}
Distributed by Meruvian Education
Output Percobaan 4 :
Distributed by Meruvian Education
Percobaan 5 : Demo Operator Relasi
public class RelationalDemo {
public RelationalDemo() {
}
public static void main(String[] args) {
int i = 37;
int j = 42;
int k = 42;
System.out.println(“Variable values…”);
System.out.println(” i = ” + i);
System.out.println(” j = ” + j);
System.out.println(” k = ” + k);
System.out.println(“Greater than…”);
System.out.println(” i > j = ” + (i > j)); //false
System.out.println(” j > i = ” + (j > i)); //true
System.out.println(” k > j = ” + (k > j)); //false
System.out.println(“Greater than or equal to…”);
System.out.println(” i >= j = ” + (i >= j)); //false
System.out.println(” j >= i = ” + (j >= i)); //true
System.out.println(” k >= j = ” + (k >= j)); //true
System.out.println(“Less than…”);
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(“Less than or equal to…”);
System.out.println(” i <= j = ” + (i <= j)); //true
System.out.println(” j <= i = ” + (j <= i)); //false
System.out.println(” k <= j = ” + (k <= j)); //true
System.out.println(“Equal to…”);
System.out.println(” i == j = ” + (i == j)); //false
System.out.println(” k == j = ” + (k == j)); //true
System.out.println(“Not equal to…”);
System.out.println(” i != j = ” + (i != j)); //true
System.out.println(” k != j = ” + (k != j)); //false
}
}
Distributed by Meruvian Education
Output Percobaan 5 :
Distributed by Meruvian Education
Percobaan 6 : Logika Boolean AND
public class TestAND {
public TestAND() {
}
public static void main( String[] args ){
int i = 0;
int j = 10;
boolean test= false;
test = (i > 10) && (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
test = (i > 10) & (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
}
}
Output Percobaan 6 :
Distributed by Meruvian Education
Percobaan 7 : Operator Logika Boolean OR
public class TestOR {
public TestOR() {
}
public static void main( String[] args ){
int i = 0;
int j = 10;
boolean test= false;
test = (i < 10) || (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
test = (i < 10) | (j++ > 9);
System.out.println(i);
System.out.println(j);
System.out.println(test);
}
}
Output Percobaan :
Distributed by Meruvian Education
Percobaan 8 : Operator Logika XOR
public class TestXOR {
public TestXOR() {
}
public static void main( String[] args ){
boolean val1 = true;
boolean 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);
}
}
Output Percobaan :
Distributed by Meruvian Education
Percobaan 9 : Operator Logika NOT
public class TestNOT {
public TestNOT() {
}
public static void main( String[] args ){
boolean val1 = true;
boolean val2 = false;
System.out.println(!val1);
System.out.println(!val2);
}
}
Output Percobaan :
Distributed by Meruvian Education
Percobaan 10 : Conditional Operator
public class ConditionalOperator {
public ConditionalOperator() {
}
public static void main( String[] args ){
String status = “”;
int grade = 80;
status = (grade >= 60)?”Passed”:”Fail”;
System.out.println( status );
}
}
Output Percobaan :
Distributed by Meruvian Education
Percobaan 11 : Conditional Operator 2
public class ConditionalOperator2 {
public ConditionalOperator2() {
}
public static void main( String[] args ){
int score = 0;
char answer = ‘a’;
score = (answer == ‘a’) ? 10 : 0;
System.out.println(“Score = ” + score );
}
}
Output Percobaan :
Distributed by Meruvian Education

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s