在 kotlin 中有一个内部数学库,我只找到平方根,但没有立方根。
import kotlin.math.sqrt
import kotlin.math.pow
fun Formule(a:Int):Double{
//no working
//rs = a.pow(1/3)
//function
retun rs
}
fun main(args: Array<String>){
val calc = Formule(9)
}
Run Code Online (Sandbox Code Playgroud) 我创建了 2 个活动,第一个我将它用作启动画面,现在在第二个活动中我在停用按钮时遇到困难,我留下代码供您理解
活动_main2.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TemaCalcActivity">
<Spinner
android:layout_width="144dp"
android:layout_height="39dp"
android:id="@+id/spnDiferencia" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginStart="8dp" app:layout_constraintStart_toEndOf="@+id/spnMP"
android:layout_marginEnd="8dp" android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@+id/textView5"/>
<Button
android:text="OK"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/button" app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="120dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="120dp" android:layout_marginTop="32dp"
app:layout_constraintTop_toBottomOf="@+id/spnMP" android:background="@drawable/button_effect"
android:textSize="18sp" android:textStyle="bold" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.026" android:onClick="onBotonFinalizar" android:enabled="false"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
Main2Activity.kt
class Main2Activity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main2)
spnDiferencia.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
when (position) {
0 -> …
Run Code Online (Sandbox Code Playgroud) 你好,让我用python演示一下我想在kotlin中实现的目标:
np.linspace(start = 0, stop = 100, num = 5)
Run Code Online (Sandbox Code Playgroud)
结果:
-------------------------
|0 | 25 | 50 | 75 | 100 |
-------------------------
Run Code Online (Sandbox Code Playgroud)
现在在科特林我如何能得到相同的结果?有类似的图书馆吗?