Skip to content

Lesson 2 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
3 changes: 0 additions & 3 deletions README.md

This file was deleted.

130 changes: 33 additions & 97 deletions src/Main.kt
Original file line number Diff line number Diff line change
@@ -1,115 +1,51 @@
package com.mawuli.helloworld //declare a package
/**
* Operators and Expression
* You can edit, run, and share this code.
* play.kotlinlang.org
*/

/**

fun main() {

//OPERATORS
val total = 100 + 50 // literal values
val result = 20 + total // variable

/**
* TYPES OF OPERATORS
* ---------------------
* 1. Arithmetic operators
* 2. Assignment operators
* 3. Comparison operators
* 4. Logical operators
*/

/**
* KOTLIN ARITHMETIC OPERATORS
* Addition (+): Adds two numbers.
* Subtraction (-): Subtracts one number from another.
* Multiplication (*): Multiplies two numbers.
* Division (/): Divides one number by another.
* Modulo (%): Returns the remainder of a division.
*
*/


val applePrice = 20
val orangePrice = 4
val fruitPrice = applePrice + orangePrice
println(fruitPrice)

val differencInPrice = applePrice - orangePrice
println(differencInPrice )

val remainder = applePrice % orangePrice
println(remainder)

/**
* KOTLIN ASSIGNMENT OPERATOR
* = Assign values to variables
*/












/**
* KOTLIN COMPARISON OPERATORS
* Equal to (==) ==
* Not equal to (!=)
* Greater than (>)
* Less than (<)
* Greater than or equal to (>=)
* Less than or equal to (<=)
*/


val person1Age = 25
val person2Age = 30

val check = person1Age == person2Age
println(check)
val check1 = person1Age != person2Age


// println("Is person 1 the same age as person 2? ${person1Age == person2Age}") // false
// println("Is person 1 not the same age as person 2? ${person1Age != person2Age}") // true
// println("Is person 1 older than person 2? ${person1Age > person2Age}") // false
// println("Is person 1 younger or the same age as person 2? ${person1Age <= person2Age}") // true



*/

// main function

fun main() { // function
val greeting = "Hello, Kotlin!" //variable
println(greeting)

//Data Types
//val userAge : Int = 24

/**
* KOTLIN LOGICAL OPERATORS
* And (&&) - Returns true if both statements are true
* Or (||) - Returns true if one of the statements is true
* Not (!) - Reverse the result, returns false if the result is true
*/
// 1. Number: Int (whole numbers), Double or Float ( fraction or decimal numbers),
//2. Text : String (more than one characters),
//3. Boolean: (True or false state)

val isSunny = true
val isWeekend = false

println("Should I go outside? ${isSunny && isWeekend}") // false
println("Can I stay inside? ${!isSunny || !isWeekend}") // true
//How to Variable
//2 ways
//1. val: read-only
//2. var: mutable variables

val PI:Double = 3.1415
val userName : String = "Mawuli Azameti"
val isOnline: Boolean = false

// userName = "John Doe"

//String template
// $
//Var
var userAge : Int = 0
userAge = 1
println("My age is " + userAge)

val language = "Kotlin"
val human = "Einstein"
println("Hello ${person1Age + person2Age}! Can we be friends?")
//best practice
//val 8bits:String = "hello"
var user_name:String = ""

val tax = 4+7
val x:Int = 1
val y:Double = 2.1

println("Hello world!")
var productId:String = ""
productId = "3243532"

}