This repository has been archived by the owner on Mar 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Main.hx
92 lines (71 loc) · 3.6 KB
/
Main.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package;
class Main {
public static function main () {
trace("--------------------------------------------------------------");
trace("--- OPERATIONS WITH INTEGER NUMBERS ---");
var i1:Int; // variable declaration without an initial value
i1 = 321; // value assignment
trace(i1);
var i2:Int = 123; // declaring a variable with initial value
trace(i2);
trace(i1 + i2); // displays result of addition
trace(i1 - i2); // displays result of subtraction
trace(i1 * i2); // displays result of multiplication
trace(i1 / i2); // displays result of division
trace(i1 % i2); // displays remainder of the division
//var i3:Int = i1 / i2; // error of type mismatch
//trace(i3);
trace("--------------------------------------------------------------");
trace("--- OPERATIONS WITH FRACTIONAL NUMBERS ---");
var f1:Float; // variable declaration without an initial value
f1 = 3.14; // value assignment
trace(f1);
var f2:Float = 41.3; // declaring a variable with initial value
trace(f2);
trace(f1 + f2); // displays result of addition
trace(f1 - f2); // displays result of subtraction
trace(f1 * f2); // displays result of multiplication
trace(f1 / f2); // displays result of division
trace(f1 % f2); // displays remainder of the division
var f3:Float = f1 / f2;
trace(f3);
trace("--------------------------------------------------------------");
trace("--- OPERATIONS WITH STRINGS ---");
var s1:String; // variable declaration without an initial value
s1 = "blah blah STR1"; // value assignment
trace(s1);
var s2:String = "qwe STR2"; // declaring a variable with initial value
trace(s2);
var s3:String = s1 + ", " + s2 + s2 + s1;
trace(s3);
trace(s3.length); // displays length of string
trace(s3.charAt(2)); // displays symbol by its index 2 in string
trace(s3.indexOf("STR0")); // displays search results of substring from the left edge of the string
trace(s3.indexOf("STR2")); // displays search results of substring from the left edge of the string
trace(s3.indexOf("STR2", 21)); // displays search results of substring from the left edge of the string from 21 index
trace(s3.lastIndexOf("STR2")); // displays search results of substring from the right edge of the string
trace(s3.split("R")); // displays results of division of string by the symbol "R"
trace(s3.split("R")[0]); // divide string by symbol "R" and display substring with index 0
trace(s3.split("R")[1]); // divide string by symbol "R" and display substring with index 1
trace(s3.substr(5, 8)); // displays substring starts from 5 and length to 8 symbols
trace(s3.substring(10, 20)); // displays substring starts from 10 and length to 20 symbols
trace(s3.toLowerCase()); // set all symbols of string to lower register and displays result
trace(s3.toUpperCase()); // set all symbols of string to upper register and displays result
// display char codes
trace("Code of new line: " + "\n".code); // display code of symbol "new line"
trace("Code of space: " + " ".code); // display code of "space"
var s4:String = "a";
trace("Code of a: " + s4.charCodeAt(0)); // display code of symbol "a"
trace("--------------------------------------------------------------");
trace("--- OPERATIONS WITH BOOLEAN ---");
var b1 : Bool; // variable declaration without an initial value
b1 = true; // value assignment
trace(b1);
var b2 : Bool = false; // declaring a variable with initial value
trace(b2);
trace(b1 && b2); // boolean AND operation
trace(b1 || b2); // boolean OR operation
trace(!b1); // boolean NOT operation
trace(!b2); // boolean NOT operation
}
}