博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The Switf programming Language 练习代码(5)
阅读量:6212 次
发布时间:2019-06-21

本文共 2669 字,大约阅读时间需要 8 分钟。

hot3.png

//

//  main.swift

//  classTest

//

//  Created by 小强 on 15/12/8.

//  Copyright © 2015 小强. All rights reserved.

//

import Foundation

var x = 0.0, y = 0.0, z = 0.0

let possibleNumber = "123";

let convertedNumber = Int(possibleNumber);

print(possibleNumber);

print(convertedNumber);

if (convertedNumber != nil)

{

    print("\(possibleNumber) has an integer value of \(convertedNumber!)");

}

else

{

    print("\(possibleNumber) could not be converted to an integer");

}

//if let actualNumber = Int(possibleNumber)

//{

//    print("\(possibleNumber) has an integer value of \(actualNumber).");

//}

//else

//{

//    print("\(possibleNumber) could not be converted to an integer.");

//}

let possibleString: String? = "An optional string.";

print(possibleString!);

let assumeString: String! = "An implicitly unwrapped optional string.";

print(assumeString);

let age = 3;

assert(age > 0, "A person's age cannot be less than zero");

let name = "world";

if name == "world" {

    

    print("hello, world")

    

} else {

    

    print("对不起,\(name),我不认识你!")

    

}

name == "world" ? print("hello world") : print("对不起,\(name),我不认识你");

for index in 1 ..< 5

{

    print("\(index) * 5 = \(index * 5)");

}

var string:Array = ["D", "o", "g", "!"];

for character in string{

    

    print(character);

    

}

print("count of string is " + "\(string.count)");

print("capacity of string is " + String(string.capacity));

let normal = "Could you help me,please?";

let shouty = normal.uppercaseString;

print(shouty);

let whispered = normal.lowercaseString;

print(whispered);

//let dogString = "Dog!???";

//for codeUnit in dogString.unicodeScalars

//{

//    print("\(codeUnit.value)");

//}

var shoppingList: [String] = ["eggs", "Milk"]

if shoppingList.isEmpty {

    

    print("The shopping list is empty.");

    

} else {

    

    print("The shopping list is not empty.")

    

}

shoppingList.append("Flour");

shoppingList += ["Baking Powder"]

print(shoppingList);

var firstItem = shoppingList[0];

print(firstItem);

shoppingList[0] = "Six eggs";

print(shoppingList);

//shoppingList[4..<6 ] = ["Bananas", "Apples"];

shoppingList.insert("Maple Syrup", atIndex: 0);

print(shoppingList);

let mapleSyrup = shoppingList.removeAtIndex(0);

print(mapleSyrup);

print(shoppingList);

for (index, value) in shoppingList.enumerate(){

    

    print("Item \(index + 1): \(value)")

    

}

var someInt = [Int]();

print("someInts is of type Int[] with \(someInt.count) items. ");

var threeDoubles = [Double](count: 3, repeatedValue: 0.0);

print(threeDoubles);

var anotherThreeDoubles = Array(count: 3, repeatedValue: 2.5);

print("anotherThreeDoubles = \(anotherThreeDoubles)");

var sixDoubles = threeDoubles + anotherThreeDoubles;

print("The sixDoubles is \(sixDoubles)");

转载于:https://my.oschina.net/u/2537892/blog/543418

你可能感兴趣的文章
HRM简介
查看>>
2015 多校联赛 ——HDU5363(快速幂)
查看>>
hdu 5464(dp)
查看>>
计算机网络--网络协议分析技术
查看>>
JAVA JDBC 调用 oracle 函数的时候,注意格式,{}, 调用关键字 call 勿必要小写。...
查看>>
iterrows() 函数对dataframe进行遍历
查看>>
11月21日
查看>>
(转)回车与换行的区别
查看>>
《自控力》读书笔记
查看>>
Linux 日常命令
查看>>
SHELL脚本 中日期的使用以及时间变量的使用
查看>>
基于Python的TCP阻塞式echo服务器
查看>>
JAVA Day3
查看>>
《深入理解计算机系统》课本第七章自学笔记——20135203齐岳
查看>>
C#的一个异常
查看>>
Oracle dba 日常使用脚本【不断更新】
查看>>
用SelectSingleNode()方法查找xml节点一直返回null
查看>>
微信小程序跨页面获取数据示例
查看>>
laravel模型中设计使用单选按钮的方法:
查看>>
关于快速幂……
查看>>