Program Java Function

Program Rumus-Rumus Lingkaran

import java.util.Scanner;
public class programling {
    public static void main(String[] args){
       
Scanner input = new Scanner(System.in);
        int pilih = 26;
       
String ulang = "y";
while(ulang.equals("y")){
       
        System.out.println("====RUMUS DALAM LINGKARAN====");
        System.out.println("[1] MENGHITUNG LUAS");
        System.out.println("[2] MENGHITUNG KELILING");
        System.out.println("[3] MENGHITUNG JURING");
        System.out.println("[4] MENGHITUNG BUSUR");
        System.out.println("[5] KELUAR");
        System.out.println("=========[1/2/3/4/5]=========");
        System.out.print("PILIHAN ANDA ? ");
try{
        pilih = input.nextInt();
        }
catch(Exception e){
        System.out.println("=====INPUTAN HARUS ANGKA=====");
        input.nextLine();
        }
       
switch (pilih) {
    case 1:{
                luas();
                break;
            }
    case 2:{
                keliling();
                break;
            }
    case 3:{
                juring();
                break;
            }
    case 4:{
                busur();
                break;
            }
    case 5:{
        System.out.println("====TERIMA KASIH Bye, Bye====");
                System.exit(5);
            }
    default:{
        System.out.println("========PILIH [1]-[5]========");
                break;
            }
            }
        System.out.println();
        System.out.print("KEMBALI KE MENU (y/n)? = ");
        ulang = input.next();
        System.out.println();
        }
        }
private static double luas(){
    System.out.println("=====[1] MENGHITUNG LUAS=====");
    System.out.println("RUMUS = 3,14 x jari-jari x jari-jari");
    System.out.println();
Scanner masuk1 = new Scanner(System.in);
            double r;
            double hasil = 0;
        try{
        System.out.print("Jari-Jari = ");
            r = masuk1.nextDouble();
        if(r<0){
                System.out.println("INPUTAN BILANGAN ASLI ATAU DESIMAL");
        }else{
                hasil = 3.14 * r * r ;
        System.out.println("Luas = "+hasil+" cm2");
        }
        }
        catch(Exception e){
            System.out.println("INPUTAN TIDAK BOLEH HURUF");
        }
        return hasil;
       
    }
private static double keliling(){
    System.out.println("=====[2] MENGHITUNG KELILING=====");
    System.out.println("RUMUS = 2 x 3,14 x jari-jari");
    System.out.println();
Scanner masuk2 = new Scanner(System.in);
            double r;
            double hasil = 0;
        try{
        System.out.print("Jari-jari = ");
            r = masuk2.nextDouble();
        if(r<0){
                System.out.println("INPUTAN BILANGAN ASLI ATAU DESIMAL");
        }else{
            hasil = 2 * 3.14 * r ;
        System.out.println("Keliling = "+hasil+" cm");
        }
        }
        catch(Exception e){
            System.out.println("INPUTAN TIDAK BOLEH HURUF");
            masuk2.nextLine();
        }
        return hasil;
    }
private static double juring(){
    System.out.println("=====[3] MENGHITUNG LUAS JURING=====");
    System.out.println("RUMUS = sudut : 360 x luas lingkaran");
    System.out.println();
Scanner masuk3 = new Scanner(System.in);
            double r, a;
            double hasil;
                double akhir = 0;
        try{
        System.out.print("Jari-jari = ");
            r = masuk3.nextDouble();
        if(r<0){
                System.out.println("INPUTAN BILANGAN ASLI ATAU DESIMAL");
        }else{
        System.out.print("Sudut = ");
            a = masuk3.nextDouble();
        if(a<0){
                System.out.println("INPUTAN BILANGAN ASLI ATAU DESIMAL");
        }else{
            hasil = 3.14 * r * r ;
            akhir = a / 360 * hasil ;
        System.out.println("Juring = "+akhir+" cm2");
        }
        }
        }
        catch(Exception e){
            System.out.println("INPUTAN TIDAK BOLEH HURUF");
            masuk3.nextLine();
        }
        return akhir;
    }
private static double busur(){
    System.out.println("=====[4] MENGHITUNG PANJANG BUSUR=====");
    System.out.println("RUMUS = sudut : 360 x keliling lingkaran");
    System.out.println();
Scanner masuk4 = new Scanner(System.in);
            double r, a;
            double hasil;
                double akhir = 0;
        try{
        System.out.print("Jari-jari = ");
            r = masuk4.nextDouble();
        if(r<0){
                System.out.println("INPUTAN BILANGAN ASLI ATAU DESIMAL");
        }else{
        System.out.print("Sudut = ");
            a = masuk4.nextDouble();
        if(a<0){
                System.out.println("INPUTAN BILANGAN ASLI ATAU DESIMAL");
        }else{
            hasil = 2 * 3.14 * r ;
            akhir = a / 360 * hasil ;
        System.out.println("Busur = "+akhir+" cm");
        }
        }
        }
        catch(Exception e){
            System.out.println("INPUTAN TIDAK BOLEH HURUF");
            masuk4.nextLine();
        }
        return akhir;
    }
}

Output



















 

Comments

Popular posts from this blog

Program Java For

Program Java Array