Exercise
Calculate values of a function
Objetive
Write a java program in java to display certain values of the function y = x^2 - 2x + 1 (using integer numbers for x, ranging from -10 to +10)
Example 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);
}
}
}