String conversion Array

Source: Internet
Author: User

Import java.util.*;
public class Zifuchuanzhuanhuanshuzu {
public static void Main (string[] args) {

System.out.println ("Please enter an array (separated by a space):");
Scanner sc = new Scanner (system.in);
Gets an input string
String s = sc.nextline ();
Cut a string into a character group by a space
string[] sa = S.split ("");
System.out.println ("The array you entered is:");
Traversing the input character group
for (String I:sa)
{
System.out.print (i + "");
}
System.out.println ();
Defines an array of type int, used to judge later
int[] n = new Int[sa.length];
for (int i = 0;i < n.length; i++)
{
Converts a character group traversal to an int array with a For loop
N[i] = Integer.parseint (Sa[i]);
}
Sorting array elements by size
for (int j = 0;j<sa.length; j + +)
{
for (int k = 0;k < sa.length; k++)
{
if (N[j] < n[k])
{
3-Line Transposition code
int temp = N[k];
N[K] = N[j];
N[J] = temp;
}
}
}
System.out.println ("From small to large sort:");
for (int x = 0;x < n.length; x + +)
{
System.out.print (N[x] + "");
}
System.out.println ("\ n" + "Minimum Value:" +n[0] + "\ n" +
"Maximum value:" + n[n.length-1]);

}
}

String conversion Array

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.