把C语言程序转换成Java
C语言源程序如下:#include<stdio.h>#include<math.h>voidmain(){floata,b,c,x1,x2;printf("请输入a,b,...
C语言源程序如下:
#include <stdio.h>
#include <math.h>
void main()
{
float a, b, c, x1, x2;
printf("请输入a, b, c的值:");
scanf("%f%f%f", &a, &b, &c);
if (b*b - 4*a*c <= 0)
printf("输入的系数不对,b2-4ac不大于0!程序退出!\n");
else
{
x1 = (-b + sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - sqrt(b*b - 4*a*c))/2*a;
printf("x1 = %.2f\n", x1);
printf("x2 = %.2f\n", x2);
}
}
即用Java编程:从键盘输入三个整型数,其分别为一元二次方程ax2+bx+c=0中a,b,c的值,判断此方程有无实数根,若有则输出其值。 展开
#include <stdio.h>
#include <math.h>
void main()
{
float a, b, c, x1, x2;
printf("请输入a, b, c的值:");
scanf("%f%f%f", &a, &b, &c);
if (b*b - 4*a*c <= 0)
printf("输入的系数不对,b2-4ac不大于0!程序退出!\n");
else
{
x1 = (-b + sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - sqrt(b*b - 4*a*c))/2*a;
printf("x1 = %.2f\n", x1);
printf("x2 = %.2f\n", x2);
}
}
即用Java编程:从键盘输入三个整型数,其分别为一元二次方程ax2+bx+c=0中a,b,c的值,判断此方程有无实数根,若有则输出其值。 展开
3个回答
展开全部
package dis;
import java.io.*;
import java.math.*;
public class dis
{
public static void main(String [] s) throws Exception
{
Float a,b,c;
double x2;
double x1;
System.out.println("请输入a, b, c的值");
BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));
a=Float.parseFloat(bReader.readLine());
b=Float.parseFloat(bReader.readLine());
c=Float.parseFloat(bReader.readLine());
if (b*b - 4*a*c <= 0)
System.out.println("输入的系数不对,b2-4ac不大于0!程序退出!");
else
{
x1 = (-b + Math.sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - Math.sqrt(b*b - 4*a*c))/2*a;
System.out.println("x1 = "+ x1);
System.out.println("x2 = "+x2);
}
return;
}
}
import java.io.*;
import java.math.*;
public class dis
{
public static void main(String [] s) throws Exception
{
Float a,b,c;
double x2;
double x1;
System.out.println("请输入a, b, c的值");
BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));
a=Float.parseFloat(bReader.readLine());
b=Float.parseFloat(bReader.readLine());
c=Float.parseFloat(bReader.readLine());
if (b*b - 4*a*c <= 0)
System.out.println("输入的系数不对,b2-4ac不大于0!程序退出!");
else
{
x1 = (-b + Math.sqrt(b*b - 4*a*c))/2*a;
x2 = (-b - Math.sqrt(b*b - 4*a*c))/2*a;
System.out.println("x1 = "+ x1);
System.out.println("x2 = "+x2);
}
return;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询