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ı değiştirin ki her zaman iki ondalık basamaklı bir double değeri yazdırsın. Bunu yapmak için printf metodunun içinde %.2f formatını kullanın:

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

String'in sonuna \n ekleyin, bu yeni bir satır ekler:

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