PS/code-up
그림파일 용량 계산
easy16
2022. 4. 22. 21:08
bmp 용량 = width*height*bits(rgb)
bits : rgb(8bit + 8bit + 8bit)
소수점 2자리 까지 반올림 (단위 : MB)
import java.util.Scanner;
class Main{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int w=sc.nextInt();
int h=sc.nextInt();
int b=sc.nextInt();
float size =(float)Math.round((float)( w*h*b)/8/1024/1024 *1000 )/1000;
System.out.println(String.format("%.2f MB", size));
}
}
ex)
100 100 4
0.00 MB
정답 : 포멧스트링을 통해 자동 반올림을 사용
import java.util.Scanner;
class Main{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int w=sc.nextInt();
int h=sc.nextInt();
int b=sc.nextInt();
//float size =(float)Math.round((float)( w*h*b)/8/1024/1024 *1000 )/1000;
System.out.println(String.format("%.2f MB", (float)( w*h*b)/8/1024/1024));
}
}