Advertisement
kuchuz

PBO-C 9 : Contoh kelilinglingkaran

Jan 11th, 2021
1,140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class kelilingLingkaran
  4. {
  5.     public static void main(String args[])
  6.     {
  7.             Scanner input = new Scanner (System.in);
  8.             double pi = 3.14;
  9.             System.out.print("Masukkan nilai jari-jari lingkaran : ");
  10.             int r = input.nextInt();
  11.             try
  12.             {
  13.                 if(r<=0)
  14.                 {
  15.                 throw new ArithmeticException();
  16.                 }
  17.                 double keliling = 2*pi*r;
  18.                 System.out.print("Keliling lingkaran adalah : ");
  19.                 System.out.println(keliling);
  20.             }
  21.             catch(ArithmeticException exception){
  22.                 System.err.printf("%nException: %s%n", exception);
  23.                 System.out.println("Nilai jari-jari tidak boleh nol atau negatif");
  24.             }      
  25.      }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement