可以用Scanner 逻辑上应该没错误 import java.util.Scanner; public class Test2 { public static String x(int a,int b,int c){ int x = b*b-4*a*c; double d; if(x<0){ return "无解"; }else{ d = Math.pow(x, 0.5); return (-b-d)/(2*a)+":"+(-b+d)/(2*a); } } public static void main(String[] args) { int m,n,q; Scanner s = new Scanner(System.in); m = s.nextInt(); n = s.nextInt(); q = s.nextInt(); String c = Test2.x(m,n,q); System.out.println(c); } }