数据流输入怎么实现 要求用文本数据流的方式输入a、b、c,求一元二次方程的根。怎么实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Main { public static void main(String[] args) { double x1,x2; double a,b,c; InputStreamReader ins = new InputStreamReader (System.in); BufferedReader br = new BufferedReader (ins); a = 0; b = 0; c = 0; x1= 0; x2= 0; try { System.out.println("Please input a(user ENTER end input)"); a = Double.parseDouble(br.readLine()); System.out.println("Please input b(user ENTER end input)"); b = Double.parseDouble(br.readLine()); System.out.println("Please input c(user ENTER end input)"); c = Double.parseDouble(br.readLine()); } catch (IOException ex) { ex.printStackTrace(); } x1 = ((0-b)+Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a); x2 = ((0-b)-Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a); System.out.println("x1 = " + x1); System.out.println("x2 = " + x2); }} 2楼正解。 x1 = ((0-b)+Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a); x2 = ((0-b)-Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a);改为if(math.pow(b,2)-4*a*c>=0){ x1 = ((0-b)+Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a); x2 = ((0-b)-Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a); System.out.println("x1 = " + x1); System.out.println("x2 = " + x2);}else System.out.println("No root!");或者try-catch一下也行 SocketChannel怎么使用指定编码读取流 外部.properties文件的读取-详见内容。 使用二维数组的好处是什么?感觉二维数组不够直观,可读性不强。 io的一个问题 怎么判断读完整个文件的所有行啊 初学java ,几个问题:netbeans 创建可重用组件 组件间的事件触发。 多谢各位高手 我想在XP SP1A 专业版下安装 Jbuilder和eclipse,请问是否会有兼容方面的问题? [求助]利用RandomAccessFile追加txt文件出现乱码 java中的字符串长度问题。 问一个数据库操作问题 有没有人帮我解决下Java图形图象处理问题呀? 不知大家遇到过没?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Main { public static void main(String[] args) { double x1,x2;
double a,b,c;
InputStreamReader ins = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (ins);
a = 0;
b = 0;
c = 0;
x1= 0;
x2= 0; try {
System.out.println("Please input a(user ENTER end input)");
a = Double.parseDouble(br.readLine());
System.out.println("Please input b(user ENTER end input)");
b = Double.parseDouble(br.readLine());
System.out.println("Please input c(user ENTER end input)");
c = Double.parseDouble(br.readLine());
} catch (IOException ex) {
ex.printStackTrace();
} x1 = ((0-b)+Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a);
x2 = ((0-b)-Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a); System.out.println("x1 = " + x1);
System.out.println("x2 = " + x2);
}
}
x1 = ((0-b)+Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a);
x2 = ((0-b)-Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a);
改为if(math.pow(b,2)-4*a*c>=0){
x1 = ((0-b)+Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a);
x2 = ((0-b)-Math.pow((Math.pow(b, 2)-4*a*c), 0.5)) / (2 * a);
System.out.println("x1 = " + x1);
System.out.println("x2 = " + x2);
}else System.out.println("No root!");
或者try-catch一下也行