langkah langkah dibawah ini menggunakan format JOptionPane dan BufferedReader
a.) Menggunakan JOptionPane
* To change this license header, choose License Headers in
Project Properties.
* To change this
template file, choose Tools | Templates
* and open the
template in the editor.
*/
package tugas3_segitiga_jop;
/**
*
* @author Admin
*/
import javax.swing.JOptionPane;
import java.io.IOException;
public class Tugas3_segitiga_Jop {
/**
* @param args the
command line arguments
*/
public static void
main(String[] args) {
double
a,b,c,t,luas,keliling;
try{
JOptionPane.showMessageDialog(null,"PROGRAM PERHITUNGAN LUAS &
KELILING SEGITIGA");
a=Double.parseDouble(JOptionPane.showInputDialog("masukan nilai
pertama :"));
b=Double.parseDouble(JOptionPane.showInputDialog("masukan nilai
kedua :"));
c=Double.parseDouble(JOptionPane.showInputDialog("masukan nilai
ketiga :"));
t=Double.parseDouble(JOptionPane.showInputDialog("masukan tinggi
segitiga :"));
luas=
0.5*a*t;
keliling=a+b+c;
JOptionPane.showMessageDialog(null, "Luas segitiga adalah "
+0.5+ " * " +a+ " * " +t+ " = " +luas+
"\nkeliling segitiga adalah " +a+ " + " +b+ " +
" +c+ " = " +keliling);
}catch
(NumberFormatException n){
JOptionPane.showMessageDialog(null,"sory input yang anda masukan
harus angka!");
}
// TODO code
application logic here
}
}
b.) Menggunakan BufferedReader
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tugas3_segitiga;
/**
*
* @author Admin
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Tugas3_segitiga {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double a,b,c,t,luas,keliling;
BufferedReader data = new BufferedReader( new InputStreamReader(System.in));
a=0;
b=0;
c=0;
t=0;
luas=0;
keliling=0;
try{
try{
System.out.println("PROGRAM PERHITUNGAN LUAS & KELILING SEGITIGA");
System.out.println("============================================");
System.out.println("masukan nilai pertama :");
a=Double.parseDouble(data.readLine());
System.out.println("masukan nilai kedua :");
b=Double.parseDouble(data.readLine());
System.out.println("masukan nilai ketiga :");
c=Double.parseDouble(data.readLine());
System.out.println("masukan tinggi segitiga :");
t=Double.parseDouble(data.readLine());
luas= 0.5*a*t;
System.out.println("Hasil luas segitiga" +0.5+ " * " +a+ " * " +t+ " = " +luas);
keliling=a+b+c;
System.out.println("hasil keliling lingkaran adalah" +a+ " + " +b+ " + " +c+ " = " +keliling);
}catch (NumberFormatException n){
System.out.println("sorry input yang anda masukan harus angka!!");
}
}catch (IOException e){
System.out.println("sorry input yang anda masukan salah");
}
// TODO code application logic heret
}
}
maaf gan kalo masih banyak kekurangan soalnya masih dalam tahap latihan juga :)









0 comments:
Post a Comment