当前位置:网站首页>Day 6 (array example)
Day 6 (array example)
2022-07-24 19:18:00 【to be__】
1、 Print Yang Hui triangle with two-dimensional array
class project {
public static void main(String[] arg) {
// Print a 10 Go Yanghui triangle
int[][] arr = new int[9][];
for(int i =0; i<arr.length; i++){
arr[i] = new int[i + 1]; // The first i Yes i+1 Elements
arr[i][0] = arr[i][i] =1; // The first and last elements are 1
if (i>1){ // Start with the third line
for(int j = 1;j<arr[i].length-1;j++){
arr[i][j] = arr[i-1][j-1] + arr[i-1][j];
}
}
}
for (int i = 0; i<arr.length;i++){
for (int j = 0;j<arr[i].length;j++){
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
}
}2、 Create a length of 6 Of int Type of the array , The required value is 1-30, At the same time, the element values are different
class project {
public static void main(String[] arg) {
int[] arr = new int[6];
for (int i=0;i<arr.length;i++){
arr[i] = (int)(Math.random()*30)+1; //[0,1) [0,30) [1,31)
for (int j=0;j<i;j++){
if (arr[i]==arr[j]){
i--; // return , Reassign
break; // Go back to the first for Loop continuation i++, That is to regenerate random numbers
}
}
}
for(int j = 0;j<arr.length;j++){
System.out.println(arr[j]);
}
}
}3、 Define a int One dimensional array of type , contain 10 Elements , Assign some random integers , Then find the maximum value of all elements , minimum value , Average , The sum of the , And output . requirement : All random numbers are double digits
import java.util.Scanner;
class project {
public static void main(String[] arg) {
Scanner scan = new Scanner(System.in);
int account = 0;
float mean = 0l;
int[] arr = new int[10];
for (int i = 0; i<arr.length;i++){
arr[i] = (int)(Math.random()*(90-10+1)+10); //[10,99]
System.out.println(arr[i]);
}
int max = arr[0];
for (int j = 0; j<arr.length;j++){
if (max < arr[j]){
max = arr[j];
}
}
System.out.println("the max number of the arr is:"+max+"\n");
int min = arr[0];
for (int j = 0; j<arr.length;j++){
if (min > arr[j]){
min = arr[j];
}
}
System.out.println("the min number of the arr is:"+min+"\n");
for (int j = 0; j<arr.length;j++){
account += arr[j];
}
System.out.println("the sum of the arr is:"+account+"\n");
mean = account/arr.length;
System.out.println("the avg of the arr is:"+mean+"\n");
}
}4、 Linear search arr Element value specified in
class project {
public static void main(String[] arg) {
String[] arr = new String[]{"aa","bb","cc","dd","ee"};
for (int i = 0; i<arr.length;i++){
System.out.println(arr[i]);
}
String dest = "ee";
boolean flag = true;
for (int j = 0; j<arr.length; j++){
if (dest.equals(arr[j])){ // stay arr[] Medium linear search and dest Equal element values , And return the index
System.out.println(" The specified value was found , Location is :"+j);
flag = false;
break;
}
}
if (flag){
System.out.println(" Did not find ");
}
}
}边栏推荐
- Wireshark simple filter rule
- mysql排序.按字段值排序
- MySQL1
- Configmanager of unity framework [JSON configuration file reading and writing]
- 2020-2021 new technology lecture course
- Tcl/tk file operation
- Getaverse, a distant bridge to Web3
- Pam4 popular science
- Easily learn pytoch transfer learning to realize surface defect inspection
- [in depth study of 4g/5g/6g topic -39]: urllc-10 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -3- how to distinguish urllc services? Detailed expl
猜你喜欢

Sequences, time series and prediction in tessorflow quizs on coursera (II)

2022 Hangdian multi school second session 1009 shuangq (Mathematics)

Convolutional Neural Networks in TensorFlow quizs on Coursera

暑期牛客多校1: I Chiitoitsu(期望dp,求逆元)

OPENGL学习(二)OPENGL渲染管线

High speed ASIC packaging trends: integration, SKU and 25g+

Common problems of multithreading and concurrent programming (to be continued)

Nacos introduction and console service installation

On July 31, 2022, the dama-cdga/cdgp data governance certification class was opened!
![[JVM learning 03] class loading and bytecode Technology](/img/b4/9482b02b58580171235fd4c36129e9.png)
[JVM learning 03] class loading and bytecode Technology
随机推荐
Oneinstack installation and configuration PHP 8.1 and MySQL 8.0-oneinstack site building novice tutorial
Tclsh array operation
Mysql数据库,子查询,union,limit篇
Literature reading: gopose 3D human pose estimation using WiFi
JS part
Installation and use of lsky Pro lancong drawing bed: a drawing bed program for online uploading and managing pictures
Wireshark simple filter rule
Nacos简介和控制台服务安装
FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 1)
Implement a proxy pool from 0
JVM方法调用
TCL programming style guide
湖仓一体释放全量数据价值,SequoiaDB v5.2线上发布会重磅来袭
MySQL8.0学习记录19 - 页区段与表空间
Sequences, time series and prediction in tessorflow quizs on coursera (I)
信道状态信息(CSI)共轭相乘去噪法
JVM method call
[understanding of opportunity-49]: three seasons and cognitive dimension
Web
OpenGL learning (IV) glut 3D image rendering