全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
精选文库在开发的时候主方法之中的代码越少越好。1、将一个给定的整型数组转置输出,例如:源数组,1 2 3 4 5 6转置之后的数组,6 5 4 3 2 1public class MyDemo public static void main(String args)int data = new int7 ;init(data) ;/ 将数组之中赋值print(data) ;System.out.println() ;reverse(data) ;print(data) ;public static void reverse(int temp)int center = temp.length / 2 ;/ 求出中心点int head = 0 ;/ 表示从前开始计算脚标int tail = temp.length - 1 ;/ 表示从后开始计算脚标for(int x = 0 ; xcenter ; x+)int t = temphead ; temphead = temptail ;temptail = t ;head + ;tail - ;public static void init(int temp)for(int x = 0 ; x temp.length; x+)tempx = x + 1 ;public static void print(int temp)for(int x = 0 ; x temp.length ; x+)System.out.print(tempx + 、) ;2、现在有如下的一个数组:int oldArr=1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5 ;要求将以上数组中值为0的项去掉,将不为0的值存入一个新的数组,生成的新数组为:int newArr=1,3,4,5,6,6,5,4,7,6,7,5 ;思路:生活中的问题解决 = 程序中的解决;1、确定出不为0的个数,这样可以开辟新数组;2、从旧的数组之中,取出内容,并将其赋给新开辟的数组;public class MyDemo public static void main(String args)int oldArr = 1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5 ;int newArr = new intcount(oldArr) ;/ 新数组fun(oldArr,newArr) ;print(newArr) ;public static void fun(int src,int data)int foot = 0 ;/ 控制新数组的脚标,datafor(int x = 0 ; x src.length; x+)if(srcx != 0)datafoot+ = srcx ;public static int count(int temp)int num = 0 ;for(int x = 0 ; x temp.length; x+)if(tempx != 0)num + ;/ 统计个数return num ;public static void print(int temp)for(int x = 0 ; x temp.length ; x+)System.out.print(tempx + 、) ;3、现在给出两个数组: 数组A:“1,7,9,11,13,15,17,19:; 数组b:“2,4,6,8,10” 两个数组合并为数组c,按升序排列。public class MyDemo public static void main(String args)int data1 = new int 1,7,9,11,13,17,19 ;int data2 = new int 2,4,6,8,10 ;int newArr = concat(data1,data2) ;java.util.Arrays.sort(newArr) ;print(newArr) ;public static int concat(int src1,int src2)int len = src1.length + src2.length ;/ 新数组的大小int arr = new intlen ;/ 新数组System.arraycopy(src1,0,arr,0,src1.length) ;/ 拷贝第一个数组System.arraycopy(src2,0,arr,src1.length,src2.length) ;/ 拷贝第二个数组return arr ;public static void print(int temp)f
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高中英语听力专项训练试卷
- 行为先予执行申请书
- 入团申请书作文100字
- 多电机协调控制调平系统的关键技术与应用研究
- 客服中心工作标准及培训手册
- 轨道交通施工专项方案制定流程
- 建筑施工劳务合同管理规范
- 节日庆典活动方案与致辞
- 企业数字化转型项目规划方案
- 新能源汽车动力系统检测报告范本
- 超高分子量聚乙烯复合材料UD布项目环境影响报告表
- GB/T 7901-2018黑胡椒
- GB/T 20241-2021单板层积材
- GB/T 1182-2018产品几何技术规范(GPS)几何公差形状、方向、位置和跳动公差标注
- 项目合作协议-非框架协议版
- 小品《你睡了没》台词剧本手稿
- DB37-T 5041-2015 城镇供水水质应急监测技术规范
- (完整)辅警考试公安基础知识考试试题库及答案
- 网约车平台服务合作协议范本
- 170位真实有效投资人邮箱
- 中等职业教育专业目录(2022年)
评论
0/150
提交评论