본문 바로가기
알고리즘풀이/정올-자바

[정올/JAVA] 583 번 함수2 - 자가진단5 세 개의 실수를 입력받아 가장 큰 수를 올림한 정수를 출력하고 가장 작은 수를 내림한 정수를 출력한 후 남은 수를 반올림한 정수를 출력하는 프로그..

by 이얏호이야호 2020. 7. 25.

공부하시는대에 도움이 됐으면 좋겠습니다.

답안코드 확인해주세요!

 

더보기
import java.util.Scanner;



public class Main {

 public static void call(double input1, double input2, double input3) {

 int count1 = 0, count2 = 0, count3 = 0;

 if (input1 > input2 && input1 > input3) {

 System.out.print((int) Math.ceil(input1) + " ");

 count1++;

 } else if (input2 > input1 && input2 > input3) {

 System.out.print((int) Math.ceil(input2) + " ");

 count2++;

 } else if (input3 > input1 && input3 > input2) {

 System.out.print((int) Math.ceil(input3) + " ");

 count3++;

 }



 if (input1 < input2 && input1 < input3) {

 System.out.print((int) Math.ceil(input1) -1 + " ");

 count1++;

 } else if (input2 < input1 && input2 < input3) {

 System.out.print((int) Math.ceil(input2) - 1 + " ");

 count2++;

 } else if (input3 < input1 && input3 < input2) {

 System.out.print((int) Math.ceil(input3) - 1 + " ");

 count3++;

 }

 if (count1 == 0)

 System.out.println(Math.round(input1));

 else if (count2 == 0)

 System.out.println(Math.round(input2));

 else if (count3 == 0)

 System.out.println(Math.round(input3));

 }



 public static void main(String args[]) {

 Scanner in = new Scanner(System.in);

 double input1 = in.nextDouble();

 double input2 = in.nextDouble();

 double input3 = in.nextDouble();



 call(input1, input2, input3);

 }

}

 

 

 


더 많은 자바코드가 보고 싶다면?

https://chuinggun.tistory.com/category/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98%ED%92%80%EC%9D%B4/%EC%A0%95%EC%98%AC-%EC%9E%90%EB%B0%94

댓글