JAVA · ОСНОВЫ · LESSON 06

Fractional numbers

Type double · about 14 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

Number with a point

For a fractional number in Java, use double. The fraction is written through a dot, even if you write a comma in an ordinary notebook.

double milk = 1.5;

✦ It's a liter and a half.

STEP 2

Count fractions.

With fractional numbers, you can add and multiply. The output will show the number along with the fractional part.

double price = 2.5;
System.out.println(price * 2);
Two goods.
2.5price× 2two5.0everything

✦ It'll be 5.0.

IN-CLASS PRACTICE

Type the code yourself

Type an example manually. Check the signs and brackets.

public class Main {
    public static void main(String[] args) {
        double price = 2.5;
        System.out.println(price * 2);
    }
}
Open the editor for class work
HOMEWORK

Solve it yourself

Create a double length with a value of 1.5. Multiply length by 2 and output the result.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework