Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- 1 ---
- val myScoreList = listOf(12,60,0,38)
- val sum = 0
- for(score: Int in myScoreList){
- sum += score //same as sum = sum+score
- }
- Log.i("",sum.toString()) //returns 100
- --- 2 ---
- val name = "Doge"
- for(character: Char in name){
- Log.i("",character.toString())
- } //logs "D","o","g","e"
- --- 3 ---
- val myEmailList = arrayListOf("john.doe@dogemail.com",
- "muhammad.li@dogemail.com",
- "xoxoILoVeKoTLiNxoxo@notdogemail.com",
- "totallyNotScammer@doggiemail.com",
- "eehoohoohoohahh@dogemail.com")
- val myDogemailList = arrayListOf<String>()
- for(email: String in myEmailList){
- val atSignIndex = email.indexOf("@")
- if(email.substring(atSignIndex+1) == "dogemail.com"){ //substring from after the "@" sign, to the end of the string
- myDogemailList.add(email)
- }
- } //now myDogemailList = ["john.doe@dogemail.com", "muhammad.li@dogemail.com", "eehoohoohoohahh@dogemail.com"]
- --- 4 ---
- val myPictureBitmap: ArrayList<ArrayList<ArrayList<Int>>> = arrayListOf(
- arrayListOf( arrayListOf(255,0,0), arrayListOf(255,127,0), arrayListOf(255,255,0) ), //row 0
- arrayListOf( arrayListOf(0,255,0), arrayListOf(0,255,255), arrayListOf(0,0,255) ), //row 1
- arrayListOf( arrayListOf(127,0,255), arrayListOf(255,255,255), arrayListOf(0,0,0) ) //row 2
- ) //column 0 //column 1 //column 2
- for(row: ArrayList<ArrayList<Int>> in myPictureBitmap){ //for each row of the picture
- for(pixel: ArrayList<Int> in row){ //for each column (pixel) in the row
- pixel[0] = 255-pixel[0]
- pixel[1] = 255-pixel[1]
- pixel[2] = 255-pixel[2] //color inversion
- }
- }
- /*from [ [ [255,0,0],[255,127,0],[255,255,0] ],
- [ [0,255,0],[0,255,255],[0,0,255] ],
- [ [127,0,255],[255,255,255],[0,0,0] ] ]
- turns to [ [ [0,255,255],[0,128,255],[0,0,255] ],
- [ [255,0,255],[255,0,0],[255,255,0] ],
- [ [128,255,0],[0,0,0],[255,255,255] ] ]
- */
Add Comment
Please, Sign In to add comment