gpt4 book ai didi

java - 如何正确调整我在此代码中打印的数字?

转载 作者:行者123 更新时间:2023-11-29 05:58:03 27 4
gpt4 key购买 nike

如何正确调整我在此代码中打印的数字?由于代码中的数字是变量,我是否需要做一些与通常调整不同的事情?

 a = 4                                                                                                      ;
b = 4 ;
c = 1 ;
x = 2 ;
Root = (-1*b + Math.sqrt( Math.pow(b,2) - 4*a*c)/ 2*a );
CoefficientOfXSquared = (-(b*x+c)/(Math.pow(x,2)) );
CoefficientOfX = (-(a*x+c)-c/x );
Constant = (-(a*Math.pow(x,2)+b*x) );
System.out.println("\n\n\t Given that: \n\t CoefficientOfXSquared = " +a );
System.out.println("\n\t CoefficientOfX = " +b );
System.out.println("\n\t Constant = " +c );
System.out.println("\n\t Root = " +x );
System.out.println("\n\n\t x = " + Root );
System.out.println("\n\t a = " + CoefficientOfXSquared );
System.out.println("\n\t b = " + CoefficientOfX );
System.out.println("\n\t c = " + Constant );
System.out.println("\n\n\n" );

如果有人能解释如何正确调整,我将不胜感激。

最佳答案

尝试使用字符串格式方法来打印它们。像这样:

double x=1234.56;
double y=78.678;
System.out.printf("%n\t Root = %12.4f", x);
System.out.printf("%n\t Constant = %12.4f%n", y);

给出:

Root          =     1234.5600
Constant = 78.6780

我假设这些是 double 。查找 printf 以获取更多信息。悬崖

关于java - 如何正确调整我在此代码中打印的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11286083/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com