


Write a Java program to solve the solution of the quadratic equation: ax^2 + bx + c
Use java to write a program to solve a quadratic equation: aX2 bX c 0
The following program passed the jdk5.0 test
import java.util.Scanner;
public class Test {
//Solution to quadratic equation of one variable
private static X fx (int a,int b,int c) throws Exception{
X x = new X();
double m = b*b - 4*a*c;
if(m>=0){
x.x1=(-1*b Math.sqrt(m))/(2*a);
x.x2=(-1*b-Math.sqrt(m))/(2*a);
return x;
}
else throw new Exception("No solution");
}
public static void main(String[] args) {
try{
//Input parameters a, b, c
Scanner cin=new Scanner(System.in);
System.out.print("a=");
int a = cin.nextInt();
System.out.print("b=");
int b = cin.nextInt();
System.out.print("c="");
int c = cin.nextInt();
//calculate
X x=fx(a,b,c);
//show
System.out.println("\n1x1="x.x1 "\nx2="x.x2);
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
//Quadratic equation solution set packaging class
class X{
double x1;
double x2;
}
Write a program in Java to solve a quadratic equation of one variable: aX2 bX c 0
public static main(String[] arg0){
if(arg0== null || arg0.length == 0){
System.out.println("Please enter parameters: a, b, c");
System.exit(0);
}
for(int i=0;i
try {
Float.parseFloat(arg0[i]);
} Catch(Exception e){
System.out.println("Please enter a number");
System.exit(0);
}
}
float a = Float.parseFloat(arg0[0]);
float b = 0;
float c = 0;
if(arg0.length >= 2){
b = Float.parseFloat(arg0[1]);
}
if(arg0.length >= 3){
c = Float.parseFloat(arg0[2]);
}
float tmp = b*b - 4*a*c;
if(tmp
System.out.println("x has no real roots");
System.exit(0);
}
if(a==0 & b==0 & c==0){
System.out.println("x has any real root");
System.exit(0);
}
float result = (-1)*b/(2*a);
if(tmp == 0){
System.out.println("x1=x2=" result);
System.exit(0);
}
float x1 = ((-1)*b java.lang.Math.sqrt(tmp))/(2*a);
float x2 = ((-1)*b-java.lang.Math.sqrt(tmp))/(2*a);
System.out.println("x1=" x1);
System.out.println("x2=" x2);
}
Java programming the root of the cubic equation a x x x b x x c x d 0
import java.io.*;
public class Test1
{
public static void main(String[] args) throws IOException
{
double a,b,c,d,x,y;
System.out.println ("Solution to cubic equation of one variable: y=ax3 bx2 cx d");
System.out.println ("Please enter a value:");
BufferedReader in1=new BufferedReader(new InputStreamReader(System.in));
a=Double.parseDouble(in1.readLine());
System.out.println("Please enter b value:");
BufferedReader in2=new BufferedReader(new InputStreamReader(System.in));
b=Double.parseDouble(in2.readLine());
System.out.println ("Please enter the c value:");
BufferedReader in3=new BufferedReader(new InputStreamReader(System.in));
c=Double.parseDouble(in3.readLine());
System.out.println ("Please enter the d value:");
BufferedReader in4=new BufferedReader(new InputStreamReader(System.in));
d=Double.parseDouble(in4.readLine());
System.out.println("Please enter x value:");
BufferedReader in5=new BufferedReader(new InputStreamReader(System.in));
x=Double.parseDouble(in5.readLine());
y=a*Math.pow(x, 3) b*Math.pow(b,2) c*x d;
System.out.println("y value is:" y);
}
}
The above is the detailed content of Write a Java program to solve the solution of the quadratic equation: ax^2 + bx + c. For more information, please follow other related articles on the PHP Chinese website!

Do you wonder how to find Resident Evil 4 saves? How to back up Resident Evil 4 saves? This post from php.cn provides 3 ways for you to back up Resident Evil 4 saves. Now, keep on your reading.

If someone tries to access your computer by inputting numerous key combinations, your computer is at a higher risk of being opened. Therefore, it is quite needed to limit the number of login attempts. How to do it? Read this php.cn post.

Cfgmgr32.dll missing errors often happen to annoy people a lot and leave some more severe issues in your Windows. So, what should you do when you run into the Cfgmgr32.dll not found issue? This post on php.cn Website will tell you some methods.

Have you ever encountered a problem where the Windows lock screen timeout is not working? Fortunately, several feasible solutions are available in this post from php.cn. Applying these fixes, you can address this annoying issue effectively.

Microsoft has released Windows 11 23H2 (the Windows 11 2023 Update) for a while. Do you want to install this update on your device? What are the new features in it? How to get this update immediately? Now, you can get the information from this php.cn

Windows Defender can protect your computer and the files on the device from attacks or infection of malware and viruses. However, sometimes, you need to bypass Windows Defender due to some reason. In this post on php.cn Website, we will introduce 3 w

When trying to copying or transferring files from mobile phones to your computer, you might get the Data supplied is of wrong type error message. If you have no idea about how to address it, this post on php.cn Website can help you out.

Want to revert changes you have made to Microsoft Excel? Here this article on php.cn Software aims to show you how to reset Excel to default settings in Windows 10 with the most effective ways.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools