は、私は[クラス名]を使用することができます[方法]のようなクラス内の変数の値を変更するには:。Kotlinのメソッドを使用して変数に新しい値を割り当てますか? Javaでは
public class Main {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
test.teste();
test.printlnvar();
}
}
class test{
public static int a = 0;
public static int b = 0;
public static void teste(){
a = 9;
b = 12;
}
public static void printlnvar(){
System.out.println("the value of A: " + a);
System.out.println("the value of B: " + b);
}
}
しかし、私はKotlinでいることをどのように行うことができますか?私がしようとしたが、結果は下記常に0変数IntColumnとIntRowためのコードである:あなたのmain
機能で
public class drawTriangle{
public var IntColumn:Int = 0;
public var IntRow:Int = 0;
fun drawTriangle(){
this.inputRowandColumn();
this.Printvalue();
}
fun inputRowandColumn(){
IntColumn = 12;
IntRow = 3;
}
fun Printvalue(){
println("the value of rows is: ${IntRow}");
println("the value of column is: ${IntColumn}");
}
}
fun main(args: Array<String>){
drawTriangle().inputRowandColumn();
drawTriangle().Printvalue();
}
あなたの答えをありがとう。しかし、他の方法はありますか? – blogtrai