class TesKeputusan {
public static void main(String[]args){
char jeniskelamin ='W';
//nested if
if(jeniskelamin=='L')
System.out.println("cowok");
else if(jeniskelamin=='P')
System.out.println("cewek");
else
System.out.println("Banci");
//ternary
System.out.println(jeniskelamin=='P'? "dia pasti cowok." :
"dia pasti cewek");
//switch case
switch(jeniskelamin) {
case'P':System.out.println("cowok");
break;
case'L':System.out.println("cewek");
break;
default : System.out.println("Banci");
break;
}
}
}
public class TesPerulangan {
public static void main(String[]args) {
int i;
//for
System.out.println("perulangan For...");
for (i=0;i<10;i++)
while (i<10) {
//while
System.out.println("perulangan while...");
i++;
}
//do while
System.out.println("perulangan Do While...");
i=0;
do {
System.out.println("perulangan ke:"+i);
i++;
}
while(i<10);
}
}
class TesTipeData {
public static void main (String[] args){
byte b=1;
short s =100;
int i=1000;
long l=10000;
char c ='a';
float f=3.14f;
double d=3.14;
boolean t=true;
final double PI=3.14;
System.out.println("byte" +b);
System.out.println("short" +s);
System.out.println("int" +i);
i=010;
System.out.println("int"+i+"octal mode");
i=0XFF;
System.out.println("int"+i+"hexa mode");
System.out.println("long"+1);
System.out.println("char"+c);
System.out.println("float"+f);
System.out.println("double"+d);
System.out.println("boolean"+t);
System.out.println("PI"+PI);
}
}
Tidak ada komentar:
Posting Komentar