매장 매출 구하기 ex

김재원·2021년 12월 7일
0

자바

목록 보기
17/41

public class arshop {
//자라
//강남점,코엑스점, 명동
//단위 백만원단위 , 평균 매출액은 만원 단위까지

public static void main(String[] args) {
	int[] shop = new int[3];
	String[] arName = {"강남점", "코엑스점","명동점"};
	Scanner sc = new Scanner(System.in);
	int sum=0;
	int cnt =0;
	double avg =0.00;
	String best = "없음";
	
	for (int i = 0; i < shop.length; i++) {
		System.out.println(arName[i] + "매출을 입력하세요(단위: 백만원)");
		shop[i]=sc.nextInt();
		sum +=shop[i];
	}
	
	System.out.println("자라 총 매출은" + sum + "백만원");
	avg = Double.parseDouble(String.format("%.2f", (double)sum / shop.length));
	System.out.println("자라 매출 평균 : "+ avg + "백만원");
	
	for (int i = 0; i < arName.length; i++) {
		if(shop[i] > avg) {
			cnt ++;
			if(cnt == 1) {best = "";} //for문 들어오면 저걸로 초기화시켜줌 만약 초기화를 안시켜주면 위에 초기 설정값으로 '없음'이 누적됨
			best += arName[i] + "\n";
		}
	}
	System.out.println("인샌티브매장\n"+best);
}

}

profile
우당탕탕 주니어 디벨로퍼

0개의 댓글