//Program increment awal akir
//Penerapan operator increment dan decrement di awal dan akhir variabel
class AwalAkhir {
public static void main(String[] args){
int x = 0;
int y = 0;
System.out.println();
System.out.println("x bernilai "+x+" dan y bernilai = "+y);
x++;
System.out.println("x++ akan menghasilkan = "+x);
++x;
System.out.println("++x akan menghasilkan = "+x);
x = 0; //nilai x di-nolkan lagi
System.out.println();
y = x++;
System.out.println("y = x++ (akhiran) akan menghasilkan");
System.out.println("x = "+x);
System.out.println("y = "+y);
System.out.println();
y = ++x;
System.out.println("y = ++x (awalan) akan menghasilkan");
System.out.println("x = "+x);
System.out.println("y = "+y);
}
}
Home » Bahasa pemrograman 1 (java) »
latihan java »
Program increment awal akir
» contoh Program increment awal akir