Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Shaping array input
Shaping array input
Import? Java . util . array;

Import? Java . util . scanner;

Public? Class? DemoArray? {

Public? Static electricity Invalid? main(String[]? args)? {

System.out.println ("Enter an array with elements separated by commas,? Like what? 1,2,3");

Scanner? Input? =? New? Scanner (system. in); //Console input

String[]? ss? =? input.nextLine()。 Trim (). Split (",");

int[]? ary? =? New? int[ss . length];

int? Total? =? 0; //Save the sum of array elements.

For what? (int? Me? =? 0; ? Me? & lt? Ss. length; ? i++)? {

ary[i]? =? integer . parse int(ss[I]);

total+= ary[I]; //Cumulative sum

}

arrays . sort(ary); //Sort from small to large

System.out.println ("sum of array elements: \ t"+total);

System.out.println ("Maximum value of array element: \ t"+ary [0]);

System.out.println ("Minimum value of array elements: \ t"+ary [ary.length-1]);

}

} Run the test

Enter a comma-separated array of elements. Like what? 1,2,3

1,3,5,4,2

Sum of array elements: 15

Maximum value of array element: 1

Minimum value of array elements: 5