# Solve Equation 3*x*x - 2*x +1 in Java Example

by Dinesh Thakur Category: Control Structures

In this example, we input the interval values a and b. Each time loop is executed the value of fx is calculated and displayed on the screen for the value of x which ranges from a to b. On each iteration, x is incremented by 0.05. This continues until x is less than equal to the value of b that user inputs.

```//Program to Solve Equation 3*x*x - 2*x +1 between values a and b

// and x varies in steps of 0.5

import java.util.Scanner; //Program uses Scanner class

public class Equation

{

public static void main(String[] args)

{

double fx , x;

int a , b ;

//Create Scanner Object to Obtain from Keyboard

Scanner input = new Scanner(System.in);

System.out.print("Enter the Interval :");

for(x=a ; x<=b ; x += 0.5)

{

fx = 3*x*x -2*x + 1;

System.out.println( "x = " + x + " and fx = " + fx);

}

}

}

``` Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles