開発環境
- OS X Mavericks - Apple(OS)
- Xcode 6.0 Beta
- Swift (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 5(Making Choices)、5.6(Exercises) 7.をSwiftで考えてみる。
5.6(Exercises) 7.
コード(Xcode)
main.swift
//
// main.swift
// sample7
//
// Created by kamimura on 8/1/14.
// Copyright (c) 2014 kamimura. All rights reserved.
//
import Foundation
for population:Float in [9000000, 10000000, 35000000, 40000000] {
for land_area:Float in [80000, 90000, 340000, 300000] {
println("population = \(Int(population)), land_area = \(Int(land_area))")
println("1.")
if population < 10000000 {
println(Int(population))
}
println("2.")
if population >= 10000000 && population <= 35000000 {
println(Int(population))
}
println("3.")
if population / land_area > 100 {
println("Densely populated")
}
println("4.")
if population / land_area > 100 {
println("Densely population")
} else {
println("Sparsely population")
}
}
}
入出力結果(Console Output)
population = 9000000, land_area = 80000 1. 9000000 2. 3. Densely populated 4. Densely population population = 9000000, land_area = 90000 1. 9000000 2. 3. 4. Sparsely population population = 9000000, land_area = 340000 1. 9000000 2. 3. 4. Sparsely population population = 9000000, land_area = 300000 1. 9000000 2. 3. 4. Sparsely population population = 10000000, land_area = 80000 1. 2. 10000000 3. Densely populated 4. Densely population population = 10000000, land_area = 90000 1. 2. 10000000 3. Densely populated 4. Densely population population = 10000000, land_area = 340000 1. 2. 10000000 3. 4. Sparsely population population = 10000000, land_area = 300000 1. 2. 10000000 3. 4. Sparsely population population = 35000000, land_area = 80000 1. 2. 35000000 3. Densely populated 4. Densely population population = 35000000, land_area = 90000 1. 2. 35000000 3. Densely populated 4. Densely population population = 35000000, land_area = 340000 1. 2. 35000000 3. Densely populated 4. Densely population population = 35000000, land_area = 300000 1. 2. 35000000 3. Densely populated 4. Densely population population = 40000000, land_area = 80000 1. 2. 3. Densely populated 4. Densely population population = 40000000, land_area = 90000 1. 2. 3. Densely populated 4. Densely population population = 40000000, land_area = 340000 1. 2. 3. Densely populated 4. Densely population population = 40000000, land_area = 300000 1. 2. 3. Densely populated 4. Densely population Program ended with exit code: 0
0 コメント:
コメントを投稿