# CodeForcess 220B Little Elephant and Array (Mo Team)

2023-01-23   ES

# 1. Seek 1! +2! +3! +···+30! Harmony, define a method

``````public class test1 {
Public Static void main (string [] args) {
// 1. Seek 1! +2! +3! +···+30! Harmony, define a method
Long Sum = 0;
for (int i = 1; i <= 30; i ++) {
SUM+= getjiecheng (i);
}
System.out.println ("Sum ="+Sum);
}

public static int getjiecheng (int a) {{
int jiecheng = 1;
for (int i = 1; i <= a; i ++) {
jiecheng*= i;
}
Return jiecheng;
}

}``````

# 2. Define the number of strange numbers in the array and the number of the number of strange numbers in the array

``````public class test2 {{
Public Static void main (string [] args) {
// 2. Define the number of unilateral array, find the number of odd numbers in the array and the number of even numbers
int [] arr = {1,3,5,6,2,56,5};

// The number of even numbers
int count = 0;
for (int i = 0; I <arr.Length; i ++) {
if (ARR [i]%2 == 0) {{
Count ++;
}
}
System.out.println ("Evencount ="+Count);
System.out.println ("Oddcount ="+(Arr.Length-Count));
}
}``````

# 3. ODARR = {1,3,5,0,0,6,0,5,4,7,7,0,5} Requires the item of 0 in the array Stay in a new array

``````public class test3 {{
Public Static void main (string [] args) {
//3.ODDARR= {1,3,5,0,6,0,5,4,7,0,5}
// Requires to remove the item of 0 in the array, and save the item that is not 0 into a new array
int [] oddarr = {1,3,5,0,0,6,0,5,4,7,0,5};

// Calculate the number of 0 in the array, prepare for the new array
int count = 0;
for (int i = 0; I <Oddarr.Length; I ++) {
if (ODDARR [i] == 0) {{
Count ++;
}
}

// Create a new array
int count1 = 0;
int [] newsr = new int
for (int i = 0; I <Oddarr.Length; I ++) {
if (ODDARR [i]! = 0) {
count1 ++;
newarr [count1-1] = Oddarr [i];
}
}
for (int m: newarr) {
System.out.print (m+"");
}

}
}``````

# 4. There are 30 0 0

Number between9, statistics 09 The number of times each number appears in each number

``````Import java.util.arrays;
public class test4 {{
Public Static void main (string [] args) {
// There are 30 numbers between 0 ~ 9, and the number of times each number appears in each number 0-9
// int random = (int) (math.random ()*10);
int [] arr = new int ;

// Assign to the array
for (int i = 0; I <arr.Length; i ++) {
arr [i] = (int) (math.random ()*10);
}

// Statistics the number of times of each number
int [] count = new int ;

for (int i = 0; i <count.length; i ++) {
for (int j = 0; j <arr.Length; j ++) {
if (arr [j] == i) {
count [i] ++;
}
}
}

System.out.println ("Value in the original array:"+Arrays.tostring (ARR));
System.out.println ("The number of times appeared from 0 ~ 9:"+Arrays.tostring (Count));
}
}``````

# 5. Add a number to the sorted number and place the number in a suitable position

``````Import java.util.arrays;
public class test5 {
Public Static void main (string [] args) {
// 5. Add a number to the sorted number, put the number in a suitable position
int [] arr = new int ;

for (int i = 0; I <arr.Length; i ++) {
arr [i] = (int) (math.random ()*30) +1;
}
System.out.println ("Original array:"+Arrays.tostring (ARR));
// Sort for arrays
// Select sorting
for (int i = 0; I <arr.Length-; i ++) {
int index = i;
for (int j = i+1; j <arr.length-1; j ++) {
if (ARR [Index]> Arr [J]) {{
Index = j;
}
}

// Implement exchange
int Temp = Arr [i];
arr [i] = Arr [Index];
arr [index] = temp;
}
System.out.println ("Organic array:+Arrays.Tostring (ARR));

// Define a number to be put in
int a = 5;

// First get the position to get the number first
int count = 0;
for (int i = 0; I <arr.Length; i ++) {
if (ARR [i] <a) {
Count ++;
}
}

// Put the new number in the array
int [] newsr = new int ;
for (int i = 0; I <newarr.Length; i ++) {
if (i <= count) {
newarr [i] = arr [i];
} else if (i == Count+1) {{
newarr [i] = a;
} else {
newarr [i] = Arr [i-1];
}
}
System.out.println ("New array after inserting numbers:"+Arrays.tostring (newarr));
}
}``````

source