Menu
Coddy logo textTech

Formatted Output

Coddy'nin Java Journey'sinin Temeller bölümünün bir parçası — ders 41 / 73.

challenge icon

Görev

Başlangıç

Çıktıyı, her zaman iki ondalık basamaklı bir double değeri yazdıracak şekilde değiştirin. Bunu yapmak için printf metodu içinde %.2f formatını kullanın:

double num = 0.0;
System.out.printf("number: %.2f", num);

Dizenin sonuna yeni bir satır ekleyen \n ifadesini ekleyin:

System.out.printf("number: %.2f\n", num);

Kendin dene

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println("Calculator App");

        Scanner scanner = new Scanner(System.in);
        double num1 = scanner.nextDouble();
        double num2 = scanner.nextDouble();

        // Perform arithmetic operations
        double sum = num1 + num2;
        double difference = num1 - num2;
        double product = num1 * num2;
        double quotient = num1 / num2;

        // Print the results
        System.out.println("Sum: " + sum);
        System.out.println("Difference: " + difference);
        System.out.println("Product: " + product);
        System.out.println("Quotient: " + quotient);
    }
}

Temeller bölümündeki tüm dersler