2014年8月22日金曜日

開発環境

Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 8(Storing Collections of Data Using Array)、8.9(Exercises) 3.をSwiftで考えてみる。

8.9(Exercises) 3.

コード(Xcode)

main.swift

//
//  main.swift
//  sample3
//
//  Created by kamimura on 8/22/14.
//  Copyright (c) 2014 kamimura. All rights reserved.
//

import Foundation

println("Hello, World!")

var appointments:[String] = ["9:00", "10:30", "14:00", "15:00", "15:30"]
println(appointments)

println("a.")
appointments.append("16:30")
println(appointments)

println("b.")
appointments = ["9:00", "10:30", "14:00", "15:00", "15:30"]
appointments += ["16:30"]
println(appointments)

println("c.")
println("a.")
appointments = ["9:00", "10:30", "14:00", "15:00", "15:30"]
var new_appointments = appointments.append("16:30")
println(appointments)
println(new_appointments)

println("b.")
appointments = ["9:00", "10:30", "14:00", "15:00", "15:30"]
let new_appointments1 = appointments + ["16:30"]
println(appointments)
println(new_appointments1)

入出力結果(Console Output)

Hello, World!
[9:00, 10:30, 14:00, 15:00, 15:30]
a.
[9:00, 10:30, 14:00, 15:00, 15:30, 16:30]
b.
[9:00, 10:30, 14:00, 15:00, 15:30, 16:30]
c.
a.
[9:00, 10:30, 14:00, 15:00, 15:30, 16:30]
()
b.
[9:00, 10:30, 14:00, 15:00, 15:30]
[9:00, 10:30, 14:00, 15:00, 15:30, 16:30]
Program ended with exit code: 0

0 コメント:

コメントを投稿