An integer array containing n elements that will be re-assembled to find the smallest number, such as {321,3,32}, with a minimum number of 321323

Source: Internet
Author: User

public class Getminnumber {
public static void Main (string[] args) {
string[] arr = null;
System.out.println ("Enter a row of integer data to be processed, separated by commas:");
Scanner input = new Scanner (system.in);
arr = Input.nextline (). Split (",");
Sort (arr);
for (String S:arr) {
System.out.print (s+ "");
}
}
public static void sort (string[] arr) {

for (int i = 0; i < arr.length-1; ++i) {

for (int j = 0; j < arr.length-1; ++j) {
int p = 0, q = 0;
String temp = "";
char[] C1 = Arr[j].tochararray ();
char[] C2 = arr[j + 1].tochararray ();
while (P < c1.length && Q < c2.length) {
if (C1[p] > C2[q]) {
temp = Arr[j];
ARR[J] = arr[j+1];
ARR[J+1] = temp;
Break
}
if (p = = C1.length-1 && q! = c2.length-1 && c1[p] > c2[q+1]) {
temp = Arr[j];
ARR[J] = arr[j+1];
ARR[J+1] = temp;
Break
}
if (q = = C2.length-1 && p! = c1.length-1 && c1[p+1] > C2[q]) {
temp = Arr[j];
ARR[J] = arr[j+1];
ARR[J+1] = temp;
Break
}
++p;
++q;
}
}
}

}
}

An integer array containing n elements that will be re-assembled to find the smallest number, such as {321,3,32}, with a minimum number of 321323

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.