Here is my homework - variables and types on Swift :) Lesson gonna be here: https://www.youtube.com/watch?v=YgEHfnD6_1c //1. Выведите в консоль минимальные и максимальные значения базовых типов, не ленитесь let minInt8 = Int8.min let maxInt8 = Int8.max let minUInt8 = UInt8.min let maxUInt8 = UInt8.max let minInt16 = Int16.min let maxInt16 = Int16.max let minUInt16 = UInt16.min let maxUInt16 = UInt16.max let minInt32 = Int32.min let maxInt32 = Int32.max let minUInt32 = UInt32.min let maxUInt32 = UInt32.max let minInt64 = Int64.min let maxInt64 = Int64.max let minUInt64 = UInt64.min let maxUInt64 = UInt64.max print("Min value of Int8 is \(minInt8)\nMax value of Int8 is \(maxInt8)\nMin value of UInt8 is \(minUInt8)\nMax value of UInt8 is \(maxUInt8)\n ") print("Min value of Int16 is \(minInt16)\nMax value of Int16 is \(maxInt16)\nMin value of UInt16 is \(minUInt16)\nMax value of UInt16 is \(maxUInt16)\n ") print("Min value of Int32 is \(minInt32)\nMax value of Int32 is \(maxInt32)\nMin value of UInt32 is \(minUInt32)\nMax value of UInt32 is \(maxUInt32)\n ") print("Min value of Int64 is \(minInt64)\nMax value of Int64 is \(maxInt64)\nMin value of UInt64 is \(minUInt64)\nMax value of UInt64 is \(maxUInt64)\n ") //2. Создайте 3 константы с типами Int, Float и Double let constA = 5 let constB : Float = 5.3 let constC = 5.457642846 //let sumOfConst = 5 + 5.3 + 5.45 //print(sumOfConst) //Создайте другие 3 константы, тех же типов: Int, Float и Double, //при чем каждая из них это сумма первых трех, но со своим типом let sumOfConstInt : Int = (constA + Int(constB) + Int(constC)) print("Integer value \(sumOfConstInt)") let sumOfConstFoat : Float = (Float(constA) + constB + Float(constC)) print("Integer value \(sumOfConstFoat)") let sumOfConstDouble : Double = (Double(constA) + Double(constB) + constC) print("Integer value \(sumOfConstDouble)") //3. Сравните Int результат суммы с Double и выведите отчет в консоль let differenceNum : Double = Double(sumOfConstInt) - sumOfConstDouble print("Difference is: \(differenceNum)") /*if Double(sumOfConstInt) < sumOfConstDouble { print("Integer value \(Double(sumOfConstInt)) < than Double value \(sumOfConstDouble)") } else if Double(sumOfConstInt) == sumOfConstDouble { print("Integer value \(Double(sumOfConstInt)) is = Double value \(sumOfConstDouble)") } else { print("Integer value \(Double(sumOfConstInt)) is > than Double value \(sumOfConstDouble)") }*/ if differenceNum > 0 { print("Int > Double") } else { print("Int < Double") }

Теги других блогов: типы Swift переменные