- To find largest number between 2 numbers
User Input: 2,3
Output: 3 is largest
import java.util.Scanner
fun main(args: Array<String>) {
print("Enter two numbers : ");
val userInput = Scanner(System.`in`)
var n1:Int = userInput.nextInt()
var n2:Int = userInput.nextInt()
if(n1>n2) print(n1)
else print(n2)
print("is the largest number")
}
Enter two numbers : 7 5 7 is the largest numberProgram
Here, we use 2 variables (above code n1
& n2
) to take numbers from the user
Now, check for the largest number using if statement
if(n1>n2){
// if true print n1
}
else {
// if false print n2
}
OR
if(n1<n2){
// if true print n2
}
else {
// if false print n1
}
Concept
Coming Soon !
QuickIn order to succeed you must fail, so that you know what not to do the next time.