by Dinesh Thakur

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.out.print("Enter the Interval :");
       a = input.nextInt(); //Read number
       b = input.nextInt(); //Read number
       for(x=a ; x<=b ; x += 0.5)
          fx = 3*x*x -2*x + 1;
          System.out.println( "x = " + x + " and fx = " + fx);

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