Calculate values of a function


Monday, November 13, 2023 Difficulty: Intermediate

Objective

Create a program Java to display certain values of the function y= x2 - 2x + 1. Ask the user for the range of integers x to show the function.

Instructions

  1. Ask the user for the range of integer numbers x.
  2. Calculate the values of the function (y= x2 - 2x + 1) for each x in the range.
  3. Display the results of the function for each x.

Input

-10
10

Output

121 100 81 64 49 36 25 16 9 4 1 0 1 4 9 16 25 36 49 64 81

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

Sums squared

Write a program in Java that requests an integer x from the user and print the result of adding it to the square.

2

Multiplication of three factors

Write a program in Java that multiplies by three factors.

3

Division and division module

Write a program in Java that requests two integers from the user (x, y) and print the result of the division and the rest of the division on a new line.

4

Division by zero

Develop a Java program that prompts the user for two numbers (x and y) and displays the result of the division operation.

5

Basic calculator

Write a program in Java that calculates the result of adding, subtracting, multiplying and dividing two numbers entered by the user.

6

Calculate dimensions of sphere

Create a program in Java for calculate the surface and volume of a sphere, given its radius.

7

Order of priority

Understand the rules of operator precedence in Java and how they influence the results of your calculations.

8

Average

Learn how to calculate the arithmetic mean of a set of numbers and how to use it in data analysis.

9

Equivalent operations

Explore how to perform equivalent mathematical operations to simplify expressions.

10

Celsius to Kelvin and Fahrenheit

The Celsius scale is centigrade, 100 divisions separate the freezing point from the boiling point of water.

11

Calculate values of a function

Apply your mathematical and programming knowledge to calculate function values in Java.

Arithmetic operators

Practice with easy and intermediate Java exercises on arithmetic operations and some types of numerical data.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

Exercises C# App

Take your Exercises C# lessons everywhere with our Android app. Download it now from Google Play