Enter an integer array and sort ID to sort its elements in ascending or descending order

Source: Internet
Author: User

Import Java.util.arrays;import Java.util.scanner;public class Intarrsot {public static void main (string[] args) {Scanner Scan = new Scanner (system.in); String str = scan.nextline (); String start = str.substring (0, 1); int num = Integer.parseint (start); String end = Str.substring (Str.length ()-1); int check = Integer.parseint (end); String stra = str.substring (2, Str.length ()-1); String []strarr = new String[num];strarr = Stra.split (""); int []intarr = new Int[num];for (int i = 0; i < intarr.length; i++) {Intarr[i] = Integer.parseint (Strarr[i]);} Arrays.sort (Intarr), if (check = = 0) {for (int i = 0; i < intarr.length-1; i++) {System.out.print (Intarr[i] + "");} System.out.println (Intarr[intarr.length-1]);} else if (check = = 1) {for (int j = intarr.length-1; j > 0; j--) {System.out.print (Intarr[j] + "");} System.out.println (Intarr[0]);}}
Compile on Eclipse no problem, do not know why Huawei OJ The result is wrong, 0 points. Ask the great God for advice.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Enter an integer array and sort ID to sort its elements in ascending or descending order

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.