[英]How to show number of asterisks to nearest thousand?
bar1 = store1/1000;
System.out.print("Store 1: ");
for(int i = 1; i <= bar1; i++)
System.out.print("*");
How to show number of "*" rounded up or down to the nearest thousand. 如何显示“ *”的数字四舍五入到最接近的千位。 Right now it just rounds down. 现在,它只是四舍五入。
use 采用
bar1 = (store1+500)/1000;
System.out.print("Store 1: ");
for(int i = 1; i <= bar1; i++)
System.out.print("*");
Use this code: 使用此代码:
double store1 = 1095;
long bar1 = Math.round(store1 / 1000);
// int bar1 = store1/1000;
System.out.print("Store 1: ");
for (int i = 1; i <= bar1; i++)
System.out.print("*");
or if stre 1 is an int and you can't change it you can use: 或者如果stre 1是一个int并且您不能更改它,则可以使用:
int store1 = 1095;
long bar1 = Math.round(((double)store1) / 1000);
// int bar1 = store1/1000;
It will round the value of store1/1000 to the nearest 1000. 它将把store1 / 1000的值四舍五入到最接近的1000。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.