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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.