当前位置:网站首页>Basic usage of two-dimensional array
Basic usage of two-dimensional array
2022-07-27 21:40:00 【Xiao Tang learns to catch babies】
= = = = = Two dimensional array ( Yang hui triangle ) = = = = = =
One 、 Definition :
1、 data type [ ][ ] Array name = new data type [ ] [ ]
2、 data type [ ][ ] Array name = { { },{ },{ },…,{ } ;
Two 、 The array length of a two-dimensional array represents
int[][] num = { {0,0,0} , {0,0,1,} , {0,2,0} , {0,0,0,} };
1、 Get the length of one-dimensional array :num[ xx ].length
example : num[ 0 ].length = 3
num[ 3 ].length = 3
2、 Get the length of the two-dimensional array :
num.length = 4
Two 、 Realization of Yang Hui triangle
Ideas : By observing the law of Yang Hui triangle :
1、 The first and last numbers in each line are 1
2、 The first 1 That's ok 1 Elements , The first n That's ok n Elements
3、 Start with the third line , Every element = The upper row of elements + The previous element of the above line
It is represented by a two-dimensional array as follows :
a[ i ] [ j ] = a[ i-1 ] [ j-1 ] + a[ i-1 ] [ j ]
So it can be realized by two-dimensional array , The code is as follows :
import java.util.Scanner;
public class ArrayYangHui{
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
System.out.println(" Please enter the number of rows of Yang Hui triangle ");
int num = myScanner.nextInt();
int arr[][] = new int[num][];
for(int i = 0 ; i < arr.length ; i++){
arr[i] = new int[i+1];// Make room for every one-dimensional array
for( int j = 0 ; j < arr[i].length ; j++ ){
if(j == 0 || j == arr[i].length - 1){
arr[i][j] = 1;// The first element and the last element are set to 1
}else{
arr[i][j] = arr[i-1][j-1] + arr[i-1][j];
// The law of Yang Hui triangle
}
System.out.print(arr[i][j]+" ");// Output each line of elements
}
System.out.println();// Wrap each line of elements
}
}
}
边栏推荐
- How to realize a good knowledge management system?
- C语言-入门-语法-指针(十二)
- Custom recycleview delete & move animation
- 看起来是线程池的BUG,但是我认为是源码设计不合理。
- A new technical director asked me to do an IP territorial function~
- "Geography language" large model Wenxin Ernie geol and its application
- Who is the sanctity of the six Chinese enterprises newly sanctioned by the United States?
- Daily news on July 15, 2022: meta announced the launch of make-a-scene: AI image generation can be controlled based on text and sketches
- Can China make a breakthrough in the future development of the meta universe and occupy the highland?
- ACM mm 2022 | Zhejiang University proposed: point cloud segmentation, active learning of new SOTA
猜你喜欢

ACM mm 2022 | Zhejiang University proposed: point cloud segmentation, active learning of new SOTA

A new technical director asked me to do an IP territorial function~

零钱通项目(两个版本)含思路详解

Search, insert and delete of hash table

腾讯云[HiFlow】| 自动化 -------HiFlow:还在复制粘贴?

Design of noise reduction link based on DSP

Box model and element positioning

异常-Exception

zibbix安装部署

"Geography language" large model Wenxin Ernie geol and its application
随机推荐
一篇文章带你走进pycharm的世界----别再问我pycharm的安装和环境配置了!!!
Up to 7.5gbps! The world's first 5nm 5g baseband snapdragon X60 release: support the aggregation of all major bands!
Recursion / backtracking (Part 1)
day 1 - day 4
How to check whether there is Tsinghua source / delete Tsinghua source and keep the default source
看起来是线程池的BUG,但是我认为是源码设计不合理。
数组扩容、排序、嵌套语句应用
In addition to "adding machines", in fact, your micro service can be optimized like this
University of Tilburg, Federal University of the Netherlands | neural data to text generation based on small datasets: comparing the added value of two semi supervised learning approvals on top of a l
Worthington血浆胺氧化酶 (PAO) 说明书
Traps and limitations of Engineering Technology Development
PostgreSQL source code (65) analysis of the working principle of globalvis, a new snapshot system
Puzzle (021) eliminate problems
"Geography language" large model Wenxin Ernie geol and its application
V2.X 同步异常,无法云端同步的帖子一大堆,同步又卡又慢
Nano semiconductor 65W gallium nitride (GAN) scheme was adopted by Xiaomi 10 Pro charger
The solution that the laptop can connect to WiFi but the browser cannot open the web page
[day_4-review, basic concepts of objects and arrays - 1]
Some operations about Anaconda (installing software and quickly opening)
ACM mm 2022 | Zhejiang University proposed: point cloud segmentation, active learning of new SOTA