Java Programming Fundamentals

Managing Java Control Flow

Java Console Output

Printing Messages

System.out.println: Prints a message and moves to a new line.
**System.out.print****: Prints a message without moving to a new line.

Printing Error Messages

System.err.println: Prints error messages.

Escape Sequences

\n: New line.
\": Double quote.

Java Console Input

Importing Scanner

Import the Scanner class from the java.util package.

Creating a Scanner Object

Create a Scanner object to read input from the console.

Taking Input

String Input: Use nextLine() to read a line of text.
Integer Input: Use nextInt() to read an integer value.

Conditional Statements

Basic Conditional Statements

if: Executes a block of code if the condition is true.
else if: Provides an additional condition if the previous if condition is false.
else: Executes if all previous conditions are false.

Nested Conditional Statements

Use nested if-else statements for multiple conditions within another if-else block.

Switch-Case Statement

Use switch-case to simplify checking a variable against multiple values.
Use break to avoid executing subsequent cases unintentionally.

Loops

For Loop

Repeats a block of code a specified number of times.

Continue Keyword

Skips the current iteration of the loop and continues with the next iteration.

Nested Loops

A loop inside another loop, useful for tasks that involve multiple layers of iteration.

While Loop

Repeats a block of code while a specified condition remains true.

Do-While Loop

Executes a block of code at least once, then repeats as long as the condition remains true.
These concepts of Managing Java Control Flow are very useful for understanding core Java. For more detailed information, refer to the Notion link:
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.