前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数据结构与算法-键盘排序

数据结构与算法-键盘排序

作者头像
cwl_java
发布2019-11-20 14:45:43
2290
发布2019-11-20 14:45:43
举报
文章被收录于专栏:cwl_Javacwl_Java

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/weixin_42528266/article/details/103117098

键盘排序
代码语言:javascript
复制
package com.cwl.arithmetic.graph;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @program: data-structure
 * @description: 键盘排序算法
 * @author: ChenWenLong
 * @create: 2019-11-15 11:41
 **/
public class KeyBroadSort {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入,需要进行排序的数字(格式 : 233,53,36),回车结束输入.");
        String nextLine = sc.nextLine();

        String[] split = nextLine.split(",");
        Integer[] temp = new Integer[split.length];

        int index = 0;
        try {
            for (String string : split) {
                temp[index++] = Integer.parseInt(string);
            }
        } catch (NumberFormatException numberFormatException) {
            System.out.println("请输入正确的内容以及格式.");
            return;
        }
        System.out.println("你输入的是 : " + Arrays.toString(temp));
        System.out.println("请选择,升序(0)还是降序(1)");
        int nextInt = sc.nextInt();
        Arrays.sort(temp);
        if(nextInt == 1) {
            StringBuilder stringBuilder = new StringBuilder(Arrays.toString(temp));
            String substring = stringBuilder.substring(1,stringBuilder.length()-1);
            StringBuilder sTemp = new StringBuilder(substring).reverse();
            System.out.println("降序 : " + sTemp);
        }else {
            System.out.println("升序 : " + Arrays.toString(temp));
        }
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-11-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 键盘排序
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档