fork download
  1. import Foundation
  2.  
  3. // 配列の中の最大値を見つける関数
  4. func findMaxValue(in array: [Int]) -> Int? {
  5. return array.max()
  6. }
  7.  
  8. // 関数の呼び出しと結果の表示
  9. let numbers = [3, 7, 2, 9, 4]
  10. if let maxValue = findMaxValue(in: numbers) {
  11. print("The maximum value in the array is \(maxValue)")
  12. } else {
  13. print("The array is empty.")
  14. }
  15.  
Success #stdin #stdout 0.02s 21020KB
stdin
Standard input is empty
stdout
The maximum value in the array is 9