【发布时间】:2021-01-11 01:26:08
【问题描述】:
我试图根据用户输入的天数使 p 翻倍,但现在无论我输入什么 p 都没有增加,我该如何解决这个问题?
Scanner dayNum = new Scanner(System.in);
System.out.print("Enter a number of days for the Double Yesterday option: ");
int d = dayNum.nextInt();
double p = .01;
double yesterday = 1000000;
String pattern = "#,###,###";
DecimalFormat df = new DecimalFormat(pattern);
System.out.println("The duration of Double Yesterday is " + d);
for (p = .01; p < d; p*=2 )
//while (p > d)
{
String penny = "$###.00";
DecimalFormat dg = new DecimalFormat(penny);
if (p < yesterday)
{
System.out.println("DOUBLE YESTERDAY FOR " + d + " DAYS GIVES MIKE " + dg.format(p) + ", WHICH IS LESS THAN " + df.format(yesterday) + " SO TAKE THE " + df.format(yesterday) + " BYEBYE");
}
System.out.println("");
break;
}
【问题讨论】:
标签: java loops for-loop while-loop