当前位置:网站首页>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

边栏推荐
- 1025 pat ranking (25 points)
- Chapter III installation and use of jupyter
- 1107 social clusters (30 points)
- 1027 colors in Mars (20 points)
- 数数据可视化实战案例(timeline轮播图,streamlit 控件年份 metabase可视化使用教程)2.0
- Matlab judge palindrome number (only numbers)
- Imitating freecodecamp to build a programming ability test platform
- 1134: Legal C identifier query
- Preliminary study on AI noise reduction evaluation system of sound network
- linux下新建Mysql数据库并导入sql文件
猜你喜欢

Review 2021, embrace change and live up to Shaohua

Three types of technical debt that programmers often encounter: code, data, and architecture

Developer practice - the future of Agora home AI audio and video

Explain service idempotency design in detail

Technology sharing | how to quickly realize audio and video online calls

Anyrtc implements application scenarios based on webrtc

Advanced functions of ES6 operation array map (), filter (), reduce()

4.2 escape characters

Talk about why I started technical writing

iMeta | 叶茂/时玉等综述环境微生物组中胞内与胞外基因的动态穿梭与生态功能...
随机推荐
C. Registration system(map)
linux下新建Mysql数据库并导入sql文件
The difference between queue and stack
At the beginning of the 2022 new year, I will send you hundreds of dry articles
Experiment of the planning group of the West University of technology -- pipeline CPU and data processing Adventure
1015 reversible primes (20 points)
1058 a+b in Hogwarts (20 points)
K - rochambau (joint search, enumeration)
Technology sharing | how to quickly realize audio and video online calls
1030 travel plan (30 points)
4.5 integer
Database connection to company database denied
Mysql database - create user name & modify permission
How to get palindrome number in MATLAB (using fliplr function)
Joint examination for management -- sample composition
NPM install --global --save --save dev differences
N - Is There A Second Way Left? (minimum spanning tree, Kruskal)
1130: find the first character that appears only once
Flask Sqlalchemy - automatically export the table model (flask sqlacodegen) & no single primary key problem ---orm (8)
Matlab judge palindrome number (only numbers)