我正在尝试构建一个新代码,现在问题是用户输入负值后,这将打印一些内容并再次提示输入值。我应该在第 69 行之后添加什么?
这是我的代码:
import java.util.Scanner;
public class bchimedochir_Math
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
double userInput;
double value;
double pow;
double sqrt;
double log;
double floor;
double ceil;
double abs;
double sqrtE;
System.out.print("How many numbers would you like to process:");
userInput = input.nextDouble();
sqrtE = Math.sqrt(Math.E);
if (userInput > 0)
{
while (true)
{
System.out.println();
System.out.print("Please enter a number: ");
value = input.nextDouble();
sqrt = Math.sqrt(value);
log = Math.log(value);
ceil = Math.ceil(value);
floor = Math.floor(value);
pow = Math.pow(value, value);
abs = Math.abs(value);
System.out.println ("Using truncated integer value for exponent of power method.");
System.out.printf("Math.pow(%.4f,%.4f)=%.4f\n", ceil, ceil, pow);
if (value < 0 )
{
System.out.println ("Cannot use negative number for square root, using absolute value instead.");
System.out.printf("Math.sqrt(%4f)=%.4f\n", abs, sqrt);
}
else
{
System.out.printf("Math.sqrt(%4f)=%.4f\n", value, sqrt);
}
if (value < 0 )
{
System.out.println ("Cannot use negative number for log method, using absolute value instead.");
System.out.printf("Math.log(%.4f)=%.4f\n", abs, log);
}
else
{
System.out.printf("Math.log(%.4f)=%.4f\n", value, log);
}
System.out.printf("Math.floor(%.4f)=%.4f\n", value, floor);
System.out.printf("Math.ceil(%.4f)=%.4f\n", value, ceil);
System.out.printf("Math.abs(%.4f)=%.4f\n", value, abs);
userInput = userInput - 1;
}
System.out.printf("\n\nThe square root of e is: \nMath.e = %.4f \n", sqrtE);
}
if (userInput < 0)
{
System.out.print("You must enter a number greater than or equal to 0.\n");
}
if (userInput == 0)
{
System.out.print("No numbers to process.\n");
System.out.printf("\n\nThe square root of e is: \nMath.e = %.4f \n", sqrtE);
}
}
}