Sabtu, 14 Maret 2015

On 06.26 by Unknown   No comments
Contoh script program java mencari luas dan keliling persegi :

/*
 * 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 luasdankelilingpersegibuf;
import java.io.*;

public class LuasDanKelilingPersegiBuf {

public static void main(String[] args) {
        double sisi,luas,keliling;
        sisi=0; luas=0; keliling=0;
        BufferedReader data = new BufferedReader (new InputStreamReader(System.in));
        try{
        try{
                System.out.println("Masukkan nilai sisi : ");
                sisi = Double.parseDouble(data.readLine());
                luas = sisi*sisi;
                keliling = 4*sisi;
                System.out.println("Luas persegi adalah : "+luas);
                System.out.println("Keliling oersegi adalah : "+keliling);
               
            }catch (NumberFormatException n){
                System.out.println("Maaf input harus angka");
            }
            }catch (IOException e){
            System.out.println("Error!");
      
    }
   
}
}


SELAMAT MENCOBA :)

0 komentar:

Posting Komentar