您现在的位置是:首页 > 文章详情

Java 数组 之 一维数组

日期:2018-07-29点击:309

http://www.verejava.com/?id=16992640551624

/** 数组分类 1. 一维数组 1.1 一维数组的定义和初始化 1.2 对一维数组的操作, 遍历,添加,插入,修改,删除,排序,查找 2. 二维数组 2.1 二维数组的定义和初始化 2.2 二维数组的遍历 3. 多维数组 4. 增强for循环 */ public class Array { public static void main(String[] args) { //一维数组的定义和初始化 //静态定义一维数组 int[] scores = { 90, 70, 50, 80, 60, 85 }; //动态定义一维数组 int[] arr = new int[6]; arr[0] = 90; arr[1] = 70; arr[2] = 50; arr[3] = 80; arr[4] = 60; arr[5] = 85; //一维数组遍历,打印出数组scores的成绩 for (int i = 0; i < scores.length; i++) { System.out.print(scores[i] + ","); } } } //数组为字符串1 public class Test1 { public static void main(String[] args) { // 书架上放了一组图书, 打印出这组图书的书名 //创建一个存放书的书架, 定义一个空的存放书的数组 0,1,2,3 String[] books = new String[4]; // 4是数组的长度 //将书存入数组 books books[0] = "乔布斯传"; books[1] = "从优秀到卓越"; books[2] = "人生不设限"; books[3] = "态度决定一切"; //打印出这组图书的书名 //System.out.println(books[2]); //数组的遍历 System.out.println(books.length); //数组的元素个数 for (int i = 0; i < books.length; i++) { System.out.println(books[i]); } } } //数组为字符串 2 public class Test2 { public static void main(String[] args) { //定义一个初始化的数组 int a = 0; String[] books = { "乔布斯传", "从优秀到卓越", "人生不设限", "态度决定一切" }; for (int i = 0; i < books.length; i++) { System.out.println(books[i]); } //王涛中考 考了 语文 ,数学,英语 分别为 90, 95, 100 int[] scores = { 90, 95, 100 }; for (int i = 0; i < scores.length; i++) { System.out.println(scores[i]); } } }

http://www.verejava.com/?id=16992640551624

原文链接:https://yq.aliyun.com/articles/620292
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章