172k views
0 votes
Write a java program to input the corresponding data to print the result of the following expression

y=ax²+bx+c

1 Answer

5 votes

Answer:

The program in Java is as follows:

import java.util.Scanner;

public class Main{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

float a, b, c, x, y;

a = input.nextFloat();

b = input.nextFloat();

c = input.nextFloat();

x = input.nextFloat();

y = a * x * x + b * x + c;

System.out.print(y); }}

Step-by-step explanation:

This declares all variables

float a, b, c, x, y;

The next 4 lines get input for a, b, c and x

a = input.nextFloat();

b = input.nextFloat();

c = input.nextFloat();

x = input.nextFloat();

This calculates the value of y using
y = ax^2 + bx + c


y = a * x * x + b * x + c;

This prints the calculated value of y

System.out.print(y);

User Deep Ghodasara
by
5.5k points