FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

25 snippets foundClear filters
JavaGetting Started

Name a value that stays fixed

Java: Use a constant declaration or the language’s constant naming convention for a fixed limit.

Java✓ Tested
JavaGetting Started

Print a number with two decimal places

Java: Format a small decimal value consistently for display.

Java✓ Tested
JavaGetting Started

Read one character from ASCII text

Java: Use a valid zero-based index to read the first character.

Java✓ Tested
JavaGetting Started

Read the beginning of a text value

Java: Extract or display the first three ASCII characters from a known nonempty string.

Java✓ Tested
JavaGetting Started

Read the first collection element

Java: Access index zero only after establishing that the collection is nonempty.

Java✓ Tested
JavaGetting Started

Repeat a fixed number of times

Java: Use a counted loop to print three numbered steps.

Java✓ Tested
JavaGetting Started

Repeat while a condition holds

Java: Count down while a positive number remains, updating the loop variable on each iteration.

Java✓ Tested
JavaGetting Started

Replace one collection element

Java: Update an existing element at a known valid index.

Java✓ Tested
JavaGetting Started

Require two conditions to be true

Java: Combine a lower and an upper bound to check whether a value is in range.

Java✓ Tested
JavaGetting Started

Run your first program

Java: Start with a complete program that prints one line. Follow the run instructions below.

Java✓ Tested
JavaGetting Started

Store a value in a named variable

Java: Give a value a descriptive name and print it.

Java✓ Tested
JavaGetting Started

Update a running count

Java: Change a variable after its initial value has been assigned.

Java✓ Tested