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));
}
}
'PS > code-up' 카테고리의 다른 글
성실한 개미 (0) | 2022.04.22 |
---|---|
설탕과자뽑기(반복문 인덱스 계산) (0) | 2022.04.22 |
함께 문제 푸는 날 (0) | 2022.04.22 |
수열 3 (0) | 2022.04.22 |
audio 파일 용량 계산 (0) | 2022.04.22 |