random 练习
Posted lq970811
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了random 练习相关的知识,希望对你有一定的参考价值。
package com.sk.skkill;
import com.sun.media.jfxmediaimpl.HostUtils;
import org.junit.jupiter.api.Test;
import java.util.*;
public class demo
{
@Test
public void xunhuan()
{
int num=10;
while (num<=100){
System.out.println(num);
num++;
if(num%6==0)
{
continue;
}
}
System.out.println("统计次数:"+(num));
}
@Test
public void character(){
Character character=new Character(‘a‘);
System.out.println(character);
System.out.println(character.compareTo(‘a‘));
System.out.println(character.compareTo(‘b‘));
System.out.println(character.isLetter(‘1‘));
System.out.println(character.isUpperCase(‘T‘));
}
@Test
public void str(){
char [] arr ={‘H‘,‘e‘,‘l‘,‘l‘,‘o‘};
String zf ="人生苦短,我学python";
System.out.println(zf);
System.out.println(arr);
String string =new String(arr);
System.out.println(string);
System.out.println(arr.equals(string));
System.out.println(zf.substring(3,6));//截取3---6 其实是5
System.out.println(string.split(",",1));
System.out.println(string.indexOf("e"));//获取下标1
System.out.println(string.charAt(1));//获取下标1的值 e
System.out.println(zf.concat("。。。"+string));//拼接字符串
System.out.println(zf.contentEquals(string));
System.out.println(string.toUpperCase());
char [] rd ={97};
Arrays.sort(rd);
System.out.println(rd);
int num =97;
for (int i=0;num<122+1;i++){
Random random=new Random();
char sjchar = (char)random.nextInt(num);
int sjint=random.nextInt(num);
System.out.println("随机后的数字:"+sjint);
System.out.println("随机后转换的字母:"+sjchar);
System.out.println();
System.out.println("----------------- ");
System.out.println(num+" "+"对应的字母 "+(char) num);
char charst =(char) num;
String uppCase = String.valueOf(charst);
System.out.println(num+" "+"对应的大写字母 "+uppCase.toUpperCase());
num++;
}
}
@Test
public void collection()
{
String array [] ={"明天会更好","为你写诗","宁夏","下一个天亮","梦醒时分","光阴的故事"};
for(String item:array){
System.out.println(item);
}
List<String> list =new ArrayList<String>();
for (int i=0;i<array.length;i++){
list.add(String.valueOf(array[i]) );//数组转换称string
}
System.out.println(list);
System.out.println(list.equals("江南"));
System.out.println(list.get(2));
}
@Test
public void whiles(){
int num =100;
int nums=0;
int sum= 0;
while (num>10)
{
System.out.println(num);
num--;
}
System.out.println("------------------------");
while (nums<10)
{
nums++;
sum +=nums;
System.out.println(sum);
}
}
}
以上是关于random 练习的主要内容,如果未能解决你的问题,请参考以下文章
Python之路(第十三篇)time模块random模块string模块验证码练习
Linux的shell脚本random相关应用和批量修改建立练习