Bir üniversitenin harcının bu yıl 10.000$ olduğunu ve her yıl %5 arttığını varsayalım.
DİL: Java
MEYDAN OKUMA:
Bir üniversitenin harç ücretinin bu yıl 10.000$ olduğunu ve her yıl %5 arttığını varsayalım. Bir yıl içinde, öğrenim 10.500 $ olacaktır. 10 yıllık öğrenim ücretini ve 10. yıldan sonra başlayan 4 yıllık öğrenim ücretinin toplam maliyetini gösteren bir program yazınız.
SOLUTION:
public class Exercise_1 { public static void main(String[] args) { int totalCost = 0; // Accumulate total cost of four years tuition int tuition = 10000; int tuitionTenthYear; for (int year = 1; year <= 14; year++) { // Increase tuition by 5% every year tuition += (tuition * 0.05); if (year > 10) // Test for after 10 years totalCost += tuition; // Accumulate tuition cost // Cost of tution in ten years if (year == 10) tuitionTenthYear = tuition; } // Display the cost of tuition in ten years System.out.println("Tuition in ten years: $" + tuitionTenthYear); // Display the cost of four years' worth of tuition after tenth year System.out.println("Total cost for four years' worth of tuition" + " after the tenth year: $" + totalCost); } }
Posted in Java, Kodlamayı Öğren