4. Introduction to Data Types

4.8. Java code

public class BasicDataTypes {

    public static void main(String[] args) {

        // Integer

        int age = 25;

        System.out.printf("Age: %d%n", age);

 

        // Float (using double for better precision, similar to Python's float)

        double height = 5.9;

        System.out.printf("Height: %.1f feet%n", height);

        // Boolean

        boolean isStudent = true;

        System.out.printf("Is student? %b%n", isStudent);

        // String

        String name = "Alice";

        System.out.printf("Name: %s%n", name);

        // Character

        char initial = 'A';

        System.out.printf("Initial: %c%n", initial);

    }

}