Package Shuzu;
Import Java.util.Scanner;
public class P1 {
public static void Main (string[] args) {
System.out.print ("Please enter the length of the array:");
Scanner scan = new Scanner (system.in);
int c= scan.nextint ();
Int[]num;
num = new Int[c];
int l=0;
for (L = 0; L < Num.length; l++) {
System.out.println ("Please enter" + (l+1) + "number of items");
int d = Scan.nextint ();
NUM[L] = D;
int sum=0;??
Sum + = Num[l];
SYSTEM.OUT.PRINTLN (sum);??
}
for (int item:num) {Traversal output array
SYSTEM.OUT.PRINTLN (item);
//}
for (int i = 0; i < num.length; i++) {Iterate through the output array
System.out.println (Num[i]);
//}
for (int i = 0; i < num.length; i++) {traverses the output array first
if (num[i]%2==1) {Find out the odd number in the array
System.out.println (Num[i]);
//}
//}
//
Find all prime numbers in an array
for (int i = 0; i < num.length; i++) {traversal output
int n = 0; define a variable
for (int j = 1; J <=num[i]; J + +) {All numbers less than or equal to num
if (num[i]%j==0) {The number of outputs is =0 for J redundancy
n++; Number of outputs for j redundancy = 0 Cumulative cycle
//}
//}
if (n==2) {When the number of outputs to j is redundant = 0 has two digits, it is prime
System.out.println (Num[i]);
//}
//}
INT[]NUM={2,3,6,9,13,32};
if (Num[0]>num[1]) {
//
//}
int temp=num[0];
NUM[0]=NUM[1];
Num[1]=temp;
The value of I (array subscript) is
for (int i = 0; i < num.length-1; i++) {Array values are sorted from small to large
for (int j = i+1; J < Num.length; J + +) {
if (Num[i]>num[j]) {
int temp=num[i];
NUM[I]=NUM[J];
Num[j]=temp;
//
//}
//}
//}
for (int item:num) {Traversal output array
SYSTEM.OUT.PRINTLN (item);
//}
System.out.println (Num[0]);
System.out.println (Num[num.length-1]);
}
}
Some basic application examples of arrays