# Calculate values of a function - Practice Exercises Java

## Lesson 3:

## Basic data types

## Exercise 3.8:

## Calculate values of a function

## Objetive:

## Create a program to display certain values of the function y = x2 - 2x + 1 (using integer numbers for x, ranging from -10 to +10)

## Source Code:

```
public class Main
{
public static void main(String[] args)
{
int y, x;
System.out.println("y = x² - 2x +1");
System.out.println();
for (x = -10; x <= 10; x++)
{
y = x * x - 2 * x + 1;
System.out.printf("x = %1$s ; y=(%1$s)² - 2*(%1$s) +1 = %2$s" + "\r\n", x, y);
}
}
}
```

Exercisey 3.8