第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

第三季隨機(jī)生成字符串,并排序出輸

標(biāo)簽:
Java
package ColleSort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class CopyOfColleSortTest {  

    //随机生成字符串
    public void TestString(){   
        Scanner scan=new Scanner(System.in);
        System.out.println("请输出要随机生成的字符串长度值:");
        int can=scan.nextInt();//接收输入值
        char[] cha=new char[can];//定义char类型数组,存放从int值
        int[] aa=new int[cha.length];//定义int类型数组,存放随机生成的数据
    int count=0;
    int num=-1;
    do{ 
        int c=(int) (Math.random()*100);
        if(c>65 && c<90){
            num++;
            aa[num]=c;
            count++;
            if(count==aa.length){
                break;
            }
        }
    }while(true);       
    char[] e=new char[aa.length];
    for(int i=0;i<aa.length;i++){
        e[i]=(char) aa[i];
    }
    String str=String.valueOf(e);//char类型转换成字符串类型

        List<String> string=new ArrayList<String>();//定义一个字符串集合
        //String str="alsdj5";//自定义一个字符串    
        for(int a=0;a<str.length()/2;a++){//设置集合的大小,在此为定义string字符串的1/3
            char newchar = 0;//定义char类型
            String newstring = "";//定义一个空字符串
            for(int i=0;i<(int)(Math.random()*10+1);i++){
                newchar=
                str.charAt((int)(Math.random()*str.length()));//随机生成10以内的整数,做为取出字符串str中字符下标号
             newstring+=String.valueOf(newchar);//char类型转换成字符串类型
            }
            System.out.println("将要添加字符串:"+newstring);       
            string.add(newstring);//将生成的字符串添加到string的集合中
        }
        //输出添加进集合中的未排序之前的字符串
        System.out.println("----The in front of Sort----");
        for(String stc:string){
            System.out.println("元素:"+stc);
        }
        //对字符集合进行排序并输出
        Collections.sort(string);
        System.out.println("----The after is Sort----");
        for(String stc:string){
            System.out.println("元素:"+stc);
        }   
    }

    public static void main(String[] args) {
        CopyOfColleSortTest cst=new CopyOfColleSortTest();//调用方法        
        cst.TestString();

    }
}
點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消