Dart - math.dart - Max / Min

목진성·2024년 11월 7일

Dart Language

목록 보기
11/12

Max docs
Min docs

print(max(0, 5)); // 둘 중 큰 값 리턴
print(min(0, 5)); // 둘 중 작은 값 리턴

import 'dart:math';

void main() {
  int a = 10;
  int b = 20;

  // int 타입의 두 숫자 중 큰 값을 찾기
  int maxInt = max(a, b);
  print('The maximum of $a and $b is $maxInt'); // 결과: The maximum of 10 and 20 is 20

  double x = 15.5;
  double y = 12.3;

  // double 타입의 두 숫자 중 큰 값을 찾기
  double maxDouble = max(x, y);
  print('The maximum of $x and $y is $maxDouble'); // 결과: The maximum of 15.5 and 12.3 is 15.5
}
profile
우주를 항해하는 여행자

0개의 댓글