java基础写法及知识点

随机数写法

int x=(int) (Math.random()*6+1);

输入

Scanner sc = new Scanner(System.in);
int id = sc.nextInt();
String name = new String();
name=sc.next(); //不读取空格,nextLine()读取空格
double salary = sc.nextDouble();

字符串

String s2=s1.toUpperCase(); //大写,小写为lower
String s3=s2.substring(1, 3); //截取,如jdk16截取后为dk

字符转换

String.valueOf();
posted @ 2022-10-10 20:58  LuMinarY-  阅读(27)  评论(0)    收藏  举报