@file:Suppress("UNREACHABLE_CODE") package com.coding.camerausingcamerax import android.os.Bundle import android.widget.Toast import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity import com.coding.camerausingcamerax.databinding.ActivityContNumberBinding import java.util.Scanner import kotlin.math.pow class ContNumber : AppCompatActivity() { var csc:String = "" private val contnumBinding: ActivityContNumberBinding by lazy { ActivityContNumberBinding.inflate(layoutInflater) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContentView(contnumBinding.root) contnumBinding.btnTakePhoto.setOnClickListener{ //main("ZEPU00372545") /*val isValid = isValidContainerNumber(contnumBinding.ContNum.text.toString()) // Print the result. if (isValid) { println("The container number is valid.") Toast.makeText(this, "ok", Toast.LENGTH_LONG).show() } else { println("The container number is invalid.") Toast.makeText(this, "sai so cont", Toast.LENGTH_LONG).show() }*/ if (validateContainerNumber("ZEPU0037254","5")==true) { /*val intent = Intent(this@ContNumber, MainActivity::class.java) intent.putExtra("Container Number", contnumBinding.ContNum.text.toString()) startActivity(intent)*/ Toast.makeText(this, "ok", Toast.LENGTH_LONG).show() }else{ Toast.makeText(this, "nhap sai so cont", Toast.LENGTH_LONG).show() } } } fun validateContainerNumber(containerNumber: String, checkDigit: String): Boolean { // Check if the container number and check digit are strings // Check if the container number has 11 characters if (containerNumber.length != 11) { return false } // Calculate the check digit using ISO 6346 standard val alphabet = "0123456789A?BCDEFGHIJK?LMNOPQRSTU?VWXYZ" var sum = 0 for (i in 0 until 10) { val char = containerNumber[i] val pos = alphabet.indexOf(char) if (pos == -1) { return false } sum += (pos * 2.0.pow(i)).toInt() } val remainder = sum % 11 val checkDigitValue = if (remainder == 10) "0" else remainder.toString() // Compare the calculated check digit with the provided check digit return checkDigitValue == checkDigit Toast.makeText(this, checkDigitValue, Toast.LENGTH_LONG).show() } } }
Write, Run & Share Kotlin code online using OneCompiler’s Kotlin online compiler for free. It’s a modern and fast online playground for Kotlin, supporting the latest version and ideal for learning, experimenting, and sharing code instantly.
Kotlin is a statically typed, modern programming language developed by JetBrains. It runs on the JVM and is fully interoperable with Java. Kotlin is concise, expressive, and safe, and it’s officially supported by Google for Android app development.
The following is a simple Kotlin program that prints a greeting:
fun main() {
println("Hello, OneCompiler!")
}
OneCompiler’s Kotlin editor supports stdin. You can provide input using the I/O tab. Here's a sample program that reads a line of input and prints a greeting:
fun main() {
print("Enter your name: ")
val name = readLine()
println("Hello, $name")
}
val name: String = "OneCompiler" // Immutable
var age: Int = 25 // Mutable
Kotlin supports type inference, so explicit types are optional:
val city = "Hyderabad"
var count = 10
val score = 85
if (score >= 50) {
println("Pass")
} else {
println("Fail")
}
for (i in 1..5) {
println(i)
}
var i = 1
while (i <= 5) {
println(i)
i++
}
var j = 1
do {
println(j)
j++
} while (j <= 5)
fun add(a: Int, b: Int): Int {
return a + b
}
fun greet(name: String) = "Hello, $name"
val items = listOf("apple", "banana", "cherry")
for (item in items) {
println(item)
}
This guide provides a quick reference to Kotlin programming syntax and features. Start coding in Kotlin using OneCompiler’s Kotlin online compiler today!