Java Pertemuan 1 - Teknik Informatika

advertisement
PEMROGRAMAN JAVA |Software Engineering Group
Java Pertemuan 1:
public class coba {
public static void main(String[] args) {
System.out.println("Jakarta, Pemalang, Pekalongan");
System.out.println("Jakarta, Tegal, Slawi");
System.out.println("Jakarta, Tegal, Purwokerto");
}
}
Menggunakan Applet
import java.awt.*;
import java.applet.*;
public class MyfirstApplet extends Applet {
public void init() {
}
1
Teknik Informatika Universitas Nasional |Quiz of Software Engineering Group
PEMROGRAMAN JAVA |Software Engineering Group
public void paint(Graphics g) {
g.drawString("Angkutan Mudik Lebaran 2011", 50, 60 );
}
}
<html>
<head>
</head>
<body bgcolor="000000">
<center>
<applet
code
= "MyfirstApplet.class"
width = "300"
height = "200"
>
</applet>
</center>
</body>
</html>
2
Teknik Informatika Universitas Nasional |Quiz of Software Engineering Group
PEMROGRAMAN JAVA |Software Engineering Group
public class coba {
public static void main(String[] args) {
//deklarasi dan inisial 3 variabel
int numMobil = 5; //jumlah Mobil
int numBis = 10; //jumlah Bis
int numKendaraan = 0;
//jumlah Kendaraan
numKendaraan =numMobil + numBis; //kalkulasi total kendaraan
// Tampilan hasil
System.out.println("Jumlah Total Kendaraan Masuk Tol Cikampek");
System.out.println("Total Kendaraan :" + numKendaraan);
}
}
3
Teknik Informatika Universitas Nasional |Quiz of Software Engineering Group
PEMROGRAMAN JAVA |Software Engineering Group
public class coba {
public static void main(String[] args) {
//calculate the radius of a pond
//which can hold 20 fish averaging in inches long
int fishCount = 20;
//number of fish is pond
int fishLength = 10; //average fish length
int inchesPerFoot = 12; //number of inches in one foot
int lengthPerSqft = 2; //fish length per square foot of surface
double radius=0.0; // pond radius in foot
int foot= 0;
int inches = 0;
double pondArea = (double)(fishCount*fishLength)/lengthPerSqft;
radius = Math.sqrt(pondArea/Math.PI);
foot=(int)Math.floor(radius);
inches = (int)Math.round(inchesPerFoot* (radius-foot));
System.out.println(
"To hold " + fishCount + " fish averaging " + fishLength +
" inches long you need a pond with an area of \n " +
4
Teknik Informatika Universitas Nasional |Quiz of Software Engineering Group
PEMROGRAMAN JAVA |Software Engineering Group
pondArea + " square foot");
System.out.println("the radius of a pond with area" + pondArea +
" square foot is " + foot + " foot" + inches + " inches.");
}
}
5
Teknik Informatika Universitas Nasional |Quiz of Software Engineering Group
Download