In the story Goldilocks and the Three Bears, each bear had a bowl of porridge to eat while sitting at his/her favourite chair. What the story didn’t tell us is that Goldilocks moved the bowls around on the table, so the bowls were not at the right seats anymore. The bowls can be sorted by weight
with the lightest
bowl being the Baby Bear’s bowl
, the medium
bowl being the Mama Bear’s bowl
and the heaviest
bowl being the Papa Bear’s bowl
. Write a program that reads in three weights and prints out the weight of Mama Bear’s bowl. You may assume all weights are positive integers less than 100.
Write a program that reads in three weights.
prints out the weight of Mama Bear’s bowl
10
5
8
8
Olympiad > Canadian Computing Competition & Olympiad > 2007 > CCC 2007 Junior Division 1번
import java.util.Arrays;
import java.util.Scanner;
public class Code6840 {
public static void main(String[] args) {
int[] bowls=new int[3];
Scanner sc=new Scanner(System.in);
for(int i=0;i<3;i++){
bowls[i]=sc.nextInt();
}
Arrays.sort(bowls);
System.out.println(bowls[1]);
}
}
배열에 세 수를 입력받아서 정렬
한다음 1
번째 인덱스 값이 엄마 곰의 그릇 무게다.