開発環境
- OS X Mavericks - Apple(OS)
- Xcode 6.0 Beta 6
- Swift (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 9(Repeating Code Using Loops)、9.10(Exercises) 12.をSwiftで考えてみる。
9.10(Exercises) 12.
コード(Xcode)
main.swift
//
// main.swift
// sample12
//
// Created by kamimura on 9/14/14.
// Copyright (c) 2014 kamimura. All rights reserved.
//
import Foundation
func removeNeg(inout num_array:[Int]) {
var i:Int = 0
while i < num_array.count {
if num_array[i] < 0 {
num_array.removeAtIndex(i)
} else {
i += 1
}
}
}
var numbers1:[Int] = [-5, 1, -3, 2]
var numbers2:[Int] = [-1, -3]
removeNeg(&numbers1)
removeNeg(&numbers2)
println(numbers1)
println(numbers2)
入出力結果(Console Output)
[1, 2] [] Program ended with exit code: 0
0 コメント:
コメントを投稿