2. Generating Outputs in Java

Summary

Java Output and String Concatenation Flowchart
        🔹 Use `System.out.print()` to print text without a new line
              │
              ▼
        🔹 Use `System.out.println()` to print text and move to a new line
              │
              ▼
        🔹 Use `+` to join text and numbers
              │
              ▼
        🔹 Java automatically converts numbers to text when using `+`
              │
              ▼
        🔹 If calculations are needed before joining text, use parentheses `()`
              │
              ▼
        ✅ Display correct output in the console!
    

Using `+` without parentheses may lead to incorrect results:

        System.out.println("10 + 5 = " + 10 + 5); 
        // Output: 10 + 5 = 105 ❌
    

Pages: 1 2 3