为了在编程中实现这一点,我们需要使用控制语句来检查条件是否满足,如果是,则执行此操作,如果没有则跳过此步骤。在kotlin 中,我们使用表达式来控制程序中的流。在本教程中,我们将学习 Kotlin 中使用的几种表达式。 if表达式 if..else表达式 if..else if..else表达式 嵌套表达式 1. Kotlin -if表达 if表达很容易理...
Thesplitfunction takes in the character that’ll be the delimiter.readIntegers()function uses a map on a split to convert each value to an Int. If you enter values lesser than the specified in the tuple, you’ll get an IndexOutOfBoundsException. We’ve used try-catch in both the input...
Thesplitfunction takes in the character that’ll be the delimiter.readIntegers()function uses a map on a split to convert each value to an Int. If you enter values lesser than the specified in the tuple, you’ll get an IndexOutOfBoundsException. We’ve used try-catch in both the input...
如果需要浮点结果,那么至少一个操作数需要为浮点数(并且请记住,就像在大多数语言中一样,浮点运算通常是不精确的): println(7/3)// 输出 2println(7/3.0)// 输出 2.3333333333333335valx =3println(7/ x)// 输出 2println(7/ x.toDouble())// 输出 2.3333333333333335 每当对相同类型的两个整数使用算术运算...
packagecom.includehelpimport java.util.*//Main Function entry Point of Programfunmain(args: Array<String>) {//Input Streamvals = Scanner(System.`in`)//Input Array Sizeprint("Enter number of elements in the array: ")valsize = s.nextInt()//Create Double array of Given sizevaldoubleArray...
val price:Double = 9.9 val msg = """ i = $i str = $str strlen = ${str.length} price = ${'$'}$price msg = ${str.replace("jun","jay")} """.trimIndent() println(msg) } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.
val: Used for read-only properties that are initialized at runtime. It can hold any value, including one determined by a function call. const val: Used for compile-time constants. It must be of a primitive or String type and is initialized at compile time. ...
As we have seen in the above example that thereadLine()function reads the input as a String. If we want to take the input in a different type such as integer, long, double then we need to either explicitly convert the input to another type or use thejava Scanner class. ...
Here, reader object of Scanner class is created. Then, the nextInt() method is called which takes integer input from the user which is stored in variable integer. To get Long, Float, double and Boolean input from the user, you can use nextLong(), nextFloat(), nextDouble() and nextBoolea...
import java.util.Scanner fun main(args: Array<String>) { val inp = Scanner(System.`in`) print("Please enter your inputs it must be the integer numbers ") var inp1 = inp.nextInt() var inp2 = inp.nextInt() var inp3 = inp.nextInt() ...