Kreis.java |
1 /** 2 * 183.592 Programmierpraxis TU Wien WS2014/15 H.Moritsch 3 * Berechnung von Kreisfumfang und -fläche 4 */ 5 public class Kreis { 6 public static void main(String[] args) { 7 8 double radius = 10.0; 9 10 double pi = 3.141592653589793; // Zahl Pi 11 12 double t; 13 14 double umfang; 15 double flaeche; 16 17 umfang = 2.0 * radius * pi; 18 flaeche = radius * radius * pi; 19 20 System.out.println(umfang); 21 System.out.println(flaeche); 22 23 // zum Vergleich: mit temporärer Variablen 24 t = radius * pi; // wird nur einmal berechnet 25 26 umfang = 2.0 * t; 27 flaeche = radius * t; 28 29 System.out.println(umfang); 30 System.out.println(flaeche); 31 32 } 33 } 34