Laboratoriya ishi Topshiriq


Download 118.6 Kb.
Sana05.01.2022
Hajmi118.6 Kb.
#222821
Bog'liq
4-lab, Alibek



Laboratoriya ishi 4.

Topshiriq

1. Java dasturlash tilida foydalanadigan kalit so’zlarni xatolikga tekshiruvchi dastur tuzing (misol uchun : Kiritiladigan qiymatlar: for, wile, do natija: while kalit so’zini kiritishda xatolik mavjud ).

2. Fayl ochish, o’qib olish dasturini tuzing va albatta faylga nom berishda paskal ko’rinishidan foydalaning.
1 .

fun main() {

var list = listOf("while","do","this","super","else","for","if")

var keywords = readLine()?.split(' ')

keywords?.forEach {string ->

if (string !in list){

list.forEach {

if (it.startsWith(string[0])){

println("you have entered '${it}' word wrong!")

}

}



}

}

}







2.

fun main(){



val fileName = "amaliyot.text"

var file = File(fileName)


val isCreatedNewFile:Boolean = file.createNewFile()

if (isCreatedNewFile){

println("file is created")

}else{


println("file is already exists")

}}


fun main() {

val fileName = "amaliyot.text"

var file = File(fileName)


var list = readFileAsLinesUsingBufferedReader(fileName)

println(list)



}

fun readFileAsLinesUsingBufferedReader(fileName: String): List



= File(fileName).bufferedReader().readLines()


fun main() {

val oldfile = File("amaliyot.text")

val newfile = File("amaliyot_new.text")


val flag = oldfile.renameTo(newfile)

if (flag) {

println("File renamed successfully")

} else {


println("Rename operation failed")

}

}




Download 118.6 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling