//
// ViewController.swift
// LearnSwift
//
// Created by ym on 15/12/24.
年
//
import
class ViewController: UIViewController
override func
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//Blow add by ym on 2015.12.24
//Project:杨闽的swift秒学作业
print("1:打印101到200之间的素数")
for var i = 0;i<=200;i=i+1
{
for (var n = 2;n<=i-1;n=n+1)
{
if(i%n==0)
{
// print("数:\(i)")
break //continue
}
if(n>=i-1)
{
print("素数:\(i)")
}
}
}
print("2:条件运算符嵌套")
var arrnum:[Int] = [98,95,30,83,70,65,50,-20]
for var j = 0; j < arrnum.count; j++ {
//print(arrnum[j])
switch
case 90 ... 100:
print("A")
case 60 ... 89:
print("B")
default:
print("C")
}
}
print("3:判断一年中第几天")
let zyear = 2015
let zmonth = 12
let zday = 24
var days = 30
var daynum = 0
for var k = 1; k < zmonth; k++ {
switch
case 1,3,5,7,8,10,12:
31;
case 4,6,9,11:
30;
case 2:
if ((zyear % 400 == 0) || ((zyear % 4 == 0) && (zyear % 100 != 0))) {
29;
else{
28;
}
default
0
}
daynum += days;
}
//
daynum = daynum + zday
print("这是一年中的第:\(daynum) 天")
//Up add by ym on 2015.12.24
}
override func
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}