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

Calculate a simple total

Java: Multiply a unit price by a quantity, then add a delivery fee.

Java✓ Tested
JavaGetting Started

Call a library function

Java: Use a standard absolute-value function with a small negative number.

Java✓ Tested
JavaGetting Started

Choose between two branches

Java: Use if and else to handle an available or empty stock count.

Java✓ Tested
JavaGetting Started

Combine text with a name

Java: Construct a greeting from a fixed prefix and a stored name.

Java✓ Tested
JavaGetting Started

Compare a value with a limit

Java: Turn a comparison into a readable yes or no result.

Java✓ Tested
JavaGetting Started

Convert known numeric text to an integer

Java: Convert a trusted literal to an integer before adding. Validate external input before converting it.

Java✓ Tested
JavaGetting Started

Count the items in a collection

Java: Read the collection’s length instead of hard-coding the loop limit.

Java✓ Tested
JavaGetting Started

Divide using a fractional number

Java: Use a floating-point operand to preserve the fractional part of a division.

Java✓ Tested
JavaGetting Started

Explain a calculation with a comment

Java: Keep the code executable while documenting why a fixed input is used.

Java✓ Tested
JavaGetting Started

Find what remains after division

Java: Use the remainder operator to count items left after forming complete groups.

Java✓ Tested
JavaGetting Started

Handle three possible outcomes

Java: Check high, normal and low values with an ordered conditional chain.

Java✓ Tested
JavaGetting Started

Measure a short text value

Java: Read the length of an ASCII string. Non-ASCII text may use multiple code units or bytes depending on the language.

Java✓ Tested