当前位置:网站首页>Compare whether the two arrays are the same
Compare whether the two arrays are the same
2022-06-30 15:36:00 【Frog claw white】
demand :
If the types of two arrays , Element number , The order and content of elements are the same, so we think this is the case 2 An array is as like as two peas. .
Please use the method to complete : Can determine whether any two integer arrays are the same , And back to true perhaps false.
analysis
1、 Define methods , receive 2 An integer array ,—> Whether parameters are required 、 return type ?
2、 Complete the logic of judgment inside the method , And return Boolean results .
Code
package com.xxf.create;
public class MethodDemo6 {
public static void main(String[] args) {
// demand : Compare the contents of any two integer arrays , Just go back to true, Otherwise return to false
int[] arr1 = {
11, 22, 33, 44};
int[] arr2 = {
11, 22, 33, 44};
System.out.println(compare(arr1, arr2));
}
//1、 Define a method , Parameters , Receive two shaping data , return type : Boolean type
public static boolean compare(int[] arr1, int[] arr2) {
//2、 Determine whether the contents of the two arrays are consistent
if (arr1.length == arr2.length) {
for (int i = 0; i < arr1.length; i++) {
if (arr1[i] != arr2[i]) {
return false;
}
}
return true;
} else {
return false;
}
}
}
Running results

边栏推荐
- Kubernetes: a comprehensive analysis of container choreography
- Expressions in if statements
- Shift operator (detailed)
- Matlab two-dimensional array example (extract data)
- Matlab calculates the factorial sum of the first n numbers (easy to understand)
- A. Theatre Square(codefore)
- Advanced functions of ES6 operation array map (), filter (), reduce()
- [ten thousand words long article] thoroughly understand load balancing
- Matlab finds prime numbers within 100
- Notes on zero basic C language learning -- first introduction -- 1 notes that mom can understand
猜你喜欢

Bye civil engineering, hello CS, can you change the certificate to the Blue Bridge Cup

Database connection to company database denied

ADB devices cannot detect the problem of Xiaomi note 3

Review 2021, embrace change and live up to Shaohua

Kubernetes: a comprehensive analysis of container choreography

C language foundation - pointer array - initialization method & constant pointer array, pointer constant array

比亚迪越来越像华为?

map reduce案例超详细讲解

How should we understand the variability of architecture design?

Experiment of the planning group of the West University of technology -- pipeline CPU and data processing Adventure
随机推荐
Scattered knowledge of C language (unfinished)
Text matching - [naacl 2022] GPL
Operator%
Quick sort (C language)
Bye civil engineering, hello CS, can you change the certificate to the Blue Bridge Cup
Matlab judges the number of same purchases
Flask Sqlalchemy - automatically export the table model (flask sqlacodegen) & no single primary key problem ---orm (8)
Flask Sqlalchemy - how to use custom query criteria ---orm (7)
Management joint examination - mathematical formula
Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)
各省GDP可视化案列,附带csv Metabase处理
Imitating freecodecamp to build a programming ability test platform
数据治理市场:亿信华辰朝左,华傲数据向右
return statement
L - Jungle roads (minimum spanning tree)
ADB devices cannot detect the problem of Xiaomi note 3
Matlab finds a prime number that is greater than a given integer and follows this integer
1107 social clusters (30 points)
Average and maximum values of MATLAB matrix
Is pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?