1.
Membuat Program
HelloWorld.java
public class HelloWorld {
public
static void main (String [] args){
System.out.println("Hello
World from Java");
}
}
2.
Membuat Program
TesTipeData.java
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 " +l);
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);
}
}
3.
Membuat Program
TesKeputusan.java
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;
}
}
}
4.
Membuat Program
TesPerulangan.java
public class TesPerulangan {
public
static void main (String[] args){
int
i;
//for
System.out.println("Perulangan
For...");
for
(i=0; i<10; i++)
System.out.println("Perulangan
ke : "+i);
//while
System.out.println("Perulangan
While...");
i=0;
while
(i<10) {
System.out.println("Perulangan
Ke : "+i);
i++;
}
//do
while
System.out.println("Perulangan
Do While...");
i=0;
do
{
System.out.println("Perulangan
Ke : "+i);
i++;
}
while
(i<10);
}
}
No comments:
Post a Comment