Senin, 17 Oktober 2011
Dasar Dasar Pemograman Java - Part 2
Lanjutin yang kemaren tentang java nih. Oooo ya ni ane persembahin khusus anak anak ICON Politeknik LP3I Bandung Khususnya anak2 MI angkatan 2011. Langsung aja dah ,,,,
Konversi
Konversi 2
public class konversi2 {
static int a,b,c; //variable global
public static void proses () {
String x,y,z;
x=”80”; //input data
y=”60”;
z=”70”;
a = Integer.parseInt(x); //konversi data
b = Integer.parseInt(y);
c = Integer.parseInt(z);
}
public static void keluaran(){
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
}
public static void main(String[] args) {
proses(); //memanggil method proses
keluaran(); //memanggil method keluaran
}
}
Konversi Temperatur
import javax.swing.*;
public class KonversiTemp {
public static void main (String[ ] args) {
double tempC, tempR, tempF;
String bilangan = JOptionPane.showInputDialog("Input Celcius:");
System.out.println("Input angka: " + bilangan);
tempC = Double.parseDouble(bilangan); //melakukan konversi
tempR = tempC * 4 / 5 ;
tempF = tempC * 9 / 5 + 32.0;
System.out.println ("Temperatur Celcius = " + tempC);
System.out.println ("Temperatur Reamur = " + tempR);
System.out.println ("Temperatur Fahrenheit = " + tempF); System.exit(0);
}
}
Konversi Tipe Data
import java.io.*;
import javax.swing.*;
public class KonverTipeData {
public static void main(String[] args) throws IOException {
float a, b, L;
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("alas ? ");
String angka1 = input.readLine();
System.out.print("tinggi ? ");
String angka2 = input.readLine();
a = Float.parseFloat(angka1);
t = Float.parseFloat(angka2);
L = (a + t)/2;
System.out.println("Luas = " + L);
}
}
Semoga bermanfaat bagi kalian ntar lanjut lagi dah ,,,,
Konversi
import javax.swing.*;
public class konversi {
public static void main(String[] args) {
String teks = JOptionPane.showInputDialog(“ Nilai ? ”);
int nilai = Integer.parseInt(teks); //konversi tipe string ke int
// variabel nilai ditampilkan
System.out.println("Nilai Anda = " + nilai);
}
}
public class konversi {
public static void main(String[] args) {
String teks = JOptionPane.showInputDialog(“ Nilai ? ”);
int nilai = Integer.parseInt(teks); //konversi tipe string ke int
// variabel nilai ditampilkan
System.out.println("Nilai Anda = " + nilai);
}
}
Konversi 2
public class konversi2 {
static int a,b,c; //variable global
public static void proses () {
String x,y,z;
x=”80”; //input data
y=”60”;
z=”70”;
a = Integer.parseInt(x); //konversi data
b = Integer.parseInt(y);
c = Integer.parseInt(z);
}
public static void keluaran(){
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
}
public static void main(String[] args) {
proses(); //memanggil method proses
keluaran(); //memanggil method keluaran
}
}
Konversi Temperatur
import javax.swing.*;
public class KonversiTemp {
public static void main (String[ ] args) {
double tempC, tempR, tempF;
String bilangan = JOptionPane.showInputDialog("Input Celcius:");
System.out.println("Input angka: " + bilangan);
tempC = Double.parseDouble(bilangan); //melakukan konversi
tempR = tempC * 4 / 5 ;
tempF = tempC * 9 / 5 + 32.0;
System.out.println ("Temperatur Celcius = " + tempC);
System.out.println ("Temperatur Reamur = " + tempR);
System.out.println ("Temperatur Fahrenheit = " + tempF); System.exit(0);
}
}
Konversi Tipe Data
import java.io.*;
import javax.swing.*;
public class KonverTipeData {
public static void main(String[] args) throws IOException {
float a, b, L;
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("alas ? ");
String angka1 = input.readLine();
System.out.print("tinggi ? ");
String angka2 = input.readLine();
a = Float.parseFloat(angka1);
t = Float.parseFloat(angka2);
L = (a + t)/2;
System.out.println("Luas = " + L);
}
}
Semoga bermanfaat bagi kalian ntar lanjut lagi dah ,,,,
Label:
Java
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar