您的位置:首页 > 新闻 > 热点要闻 > Kotlin学习02-变量、常量、整数、浮点数、操作符、元组、包、导入

Kotlin学习02-变量、常量、整数、浮点数、操作符、元组、包、导入

2024/12/27 10:07:06 来源:https://blog.csdn.net/qq_36437991/article/details/141301921  浏览:    关键词:Kotlin学习02-变量、常量、整数、浮点数、操作符、元组、包、导入

变量、常量、整数、浮点数、操作符、元组、包、导入

Book.kt

package com.wujialiang.packclass Book {var title: String = "Hello"
}val PI = 3.14;
val E = 2.178;

Main.kt

//引入包
//import com.wujialiang.pack.Book;
import com.wujialiang.pack.*;
//重命名导入
import com.wujialiang.pack.Book as TestBook;
fun addPIAndE()=PI+E;fun main() {//常量val constant = "我是常量";//constVar ="我要改变";println(constant);//变量var variable = "我是变量";println(variable);variable = "我能改变";println(variable);//整数类型val int: Int = 1;println(int);val long: Long = 1L;println(long);val double: Double = 1.0;println(double);val float: Float = 1.0f;println(float);val octal: Int = 0xACF;println(octal);val hexadecimal: Int = 0b01010111;println(hexadecimal);//类型转换val intToLong = int.toLong();println(intToLong);val intToChar = 97.toChar();println(intToChar);//左移 1左移2val result1 = 1 shl 2;println(result1);//右移 1右移2val result2 = 1 shr 2;println(result2);//无符号右移val result3 = 1 ushr 2;println(result3);//与或非异或val result4 = 1 and 0x00001111;println(result4);val result5 =  1 or 0x00001111;println(result5);val result6 = 1 xor 0x00001111;println(result6);//取反val result7 = 1.inv();println(result7);val pi = 3.1415926;println("圆周率为${pi}");val bool:Boolean = false;println(bool);//元组val grade = Triple("一级","二级","三级");println("${grade.first}-${grade.second}-${grade.third}");//可空类型var address:String? = null;address="济南市";println(address);var a =3;a = -100;println(+a)//-100println(-a)//100//操作符 + - * / % -= += *= /= > < >= <= ==var r=1;r /=1;println(r);//import导入和重命名val result8 = addPIAndE();println(result8);val book =  TestBook();println(book.title);
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com