对数字段进行排序,String,Integer,Arrays,ArrayList,Scanner

来源:互联网 发布:武术器械大全 淘宝 编辑:程序博客网 时间:2024/04/30 01:51
package test;import java.util.ArrayList;import java.util.Arrays;import java.util.Scanner;public class LianXi {    public static void main(String[] args) {        System.out.println("Enter the number, enter 's' to exit:");        ArrayList<Integer> list = new ArrayList<>();        String s = "";        do {            Scanner scanner = new Scanner(System.in);            s = scanner.nextLine();            if (s.equals("s")) {                break;            } else {                list.add(Integer.parseInt(s));            }        } while (!s.equals("s"));        int[] ints = new int[list.size()];        for (int i = 0; i < list.size(); i++) {            ints[i] = list.get(i);        }        Arrays.sort(ints);        for (int i : ints) {            System.out.println(i + "");        }    }}/*Stringboolean     equals(Object anObject)     // ""Compares this string to the specified object.Integerstatic int  parseInt(String s)Parses the string argument as a signed decimal integer.static int  parseInt(String s, int radix)Parses the string argument as a signed integer in the radix specified by the second argument.Arraysstatic void     sort(byte[] a)Sorts the specified array into ascending numerical order.static void     sort(byte[] a, int fromIndex, int toIndex)Sorts the specified range of the array into ascending order.ArrayList<object>boolean     add(E e)Appends the specified element to the end of this list.E   get(int index)Returns the element at the specified position in this list.remove()set()size()contains()ScannerScanner(InputStream source)Constructs a new Scanner that produces values scanned from the specified input stream.String  nextLine()Advances this scanner past the current line and returns the input that was skipped. */
原创粉丝点击