java各种数据类型的数组元素的默认值
public class DataTypeDefaultValue {public static void main(String[] args) {// string类型数组的默认值null// 对于引用类型的属性的默认值是null,如String类型System.out.println("查看String类型中数组的默认值:");String[] str = new String[4];str[0] = "aa";str[1] = "bb";str[2] = "cc";for (int i = 0; i < 4; i++) {System.out.println(str[i]);}// 对于short,int,long,byte而言,创建数组的默认值是0System.out.println("查看int类型数组的默认值:");int[] score = new int[4];score[0] = 90;score[1] = 89;score[2] = 34;for (int i = 0; i < score.length; i++) {System.out.println(score[i]);}System.out.println("查看short类型数组的默认值:");short[] score1 = new short[4];score1[0] = 90;for (int i = 0; i < score1.length; i++) {System.out.println(score1[i]);}System.out.println("查看long类型数组的默认值:");long[] score2 = new long[4];score2[0] = 90;for (int i = 0; i < score2.length; i++) {System.out.println(score2[i]);}System.out.println("查看byte类型数组的默认值:");byte[] score3 = new byte[4];score3[0] = 90;for (int i = 0; i < score3.length; i++) {System.out.println(score3[i]);}// 对于float double而言,默认值是0.0System.out.println("查看float类型数组的默认值:");float[] score4 = new float[4];score4[0] = 23;for (int i = 0; i < score4.length; i++) {System.out.println(score4[i]);}System.out.println("查看double类型数组的默认值:");double[] score5 = new double[4];score5[0] = 45;for (int i = 0; i < score5.length; i++) {System.out.println(score5[i]);}// 对于char类型// char类型数组的默认值是空格System.out.println("查看char类型数组的默认值:");char[] ch = new char[4];ch[0] = 'p';for (int i = 0; i < ch.length; i++) {System.out.println(ch[i]);}// 对于boolean类型的数组默认值// boolean类型数组的默认值是falseSystem.out.println("查看boolean数组的默认值:");boolean[] b = new boolean[4];b[0] = true;for (int i = 0; i < b.length; i++) {System.out.println(b[i]);}/// 引用类型数组的默认值是nullclass Person {}System.out.println("查看引用类型的数组默认值:");Person[] p = new Person[4];for (int i = 0; i < p.length; i++) {System.out.println(p[i]);}}}
运行结果:
查看String类型中数组的默认值:aabbccnull查看int类型数组的默认值:9089340查看short类型数组的默认值:90000查看long类型数组的默认值:90000查看byte类型数组的默认值:90000查看float类型数组的默认值:23.00.00.00.0查看double类型数组的默认值:45.00.00.00.0查看char类型数组的默认值:p
java各种数据类型的数组元素的默认值的更多相关文章
- Java 创建数组的方式, 以及各种类型数组元素的默认值
①创建数组的方式3种 ①第1种方法 public class MyTest { public static void main(String[] args){ //method 1 int[] arr ...
- C++:map用法及元素的默认值
C++:map用法 一.map基本用法 键值对 第一个参数为键的类型,第二个参数为值的类型. 源代码 #include <iostream> #include <string> ...
- 关于Java读取mysql中date类型字段默认值'0000-00-00'的问题
今天在做项目过程中,查询一个表中数据时总碰到这个问题: java.sql.SQLException:Value '0000-00-00' can not be represented as ...
- 【转】MySQL datetime数据类型设置当前时间为默认值
转自http://blog.csdn.net/u014694759/article/details/30295285 方法一: MySQL目前不支持列的Default 为函数的形式,如达到你某列的默认 ...
- (转)日期类型的input元素设置默认值为当天
原文地址 html5的form元素对日期时间有丰富的支持 <input type="date"> <input type="time"> ...
- 日期类型的input元素设置默认值为当天
html文件:<input name="" type="date" value="" id="datePicker" ...
- (Java)怎么去掉字符串数组中重复的值?
String fdbs = "WXB,WXA,FDA,WXB"; String[] str = fdbs.split(","); Set set = new H ...
- c#中的数据类型简介(数组)
c#中的数据类型简介(数组) 数组定义 可以将数组看成相同数据类型的一组或多组数据,包括一维数组,多维数组和交错数组. 数值数组元素的默认值设置为零,而引用元素的默认值设置为 null. 交错数组是指 ...
- Java基础知识笔记第二章:基本数据类型与数组
标识符和关键字 标识符: 1:字母,数字,下划线,美元符号 2.不能以数字开头 3.标识符不能是:true false null(尽管true false null不是java的关键字 ...
随机推荐
- Linux centos 推拉、共享、监控的设置的分享
新建四台虚拟机 打开第一台连接shell更改主机名.网卡 backup 1.主机名网卡配置 [root@jytcentos7.6 ~]# hostnamectl set-hostname backup ...
- React笔记:快速构建脚手架(1)
1. Create React APP React官方提供的脚手架工程Create React App:https://github.com/facebook/create-react-app Cre ...
- java 基本数据类型初始值(默认值)
1.int类型定义的数组,初始化默认是0 2.String类型定义的数组,默认值是null 3.char类型定义的数组,默认值是0对应的字符 4.double类型定义的数组,默认值是0.0 5.flo ...
- codeforces675D
Tree Construction CodeForces - 675D During the programming classes Vasya was assigned a difficult pr ...
- 【CF1157F】Maximum Balanced Circle
题目大意:给定一个长度为 N 的序列,求是否能够从序列中选出一个集合,使得这个集合按照特定的顺序排成一个环后,环上相邻的点之间的权值差的绝对值不超过 1. 题解:集合问题与序列顺序无关,因此可以先将序 ...
- 基于 Markdown 编写接口文档
最近公司开发项目需要前后端分离,这样话就设计到后端接口设计.复杂功能需要提供各种各样的接口供前端调用,因此编写API文档非常有必要了 网上查了很多资料,发现基于Markdown编写文档是一种比较流行而 ...
- python验证卡普耶卡(D.R.Kaprekar)6174猜想
1955年,卡普耶卡(D.R.Kaprekar)对4位数字进行了研究,发现一个规律: 对任意各位数字不相同的4位数,使用各位数字能组成的最大数减去能组成的最小数,对得到的差重复这个操作,最终会得到61 ...
- Apache Hadoop 2.9.2 的YARN High Available 模式部署
Apache Hadoop 2.9.2 的YARN High Available 模式部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.环境准备 1>.官方文档(htt ...
- 装饰器模式-Decorator(Java实现)
装饰器模式-Decorator(Java实现) 装饰器模式允许向一个现有的对象添加新的功能, 同时又不改变其结构. 其中 "现有对象"在本文中是StringDisplay类. 添加 ...
- Golang入门教程(二)Ubuntu16.04下安装golang(实例:Golang 定时任务管理器)
通过两种方式安装 一.通过apt-get安装1.安装 sudo apt-get install golang 2.设置GOPATH变量 GOPATH是扩展库的目录,Go先搜索标准库目录,然后搜索GOP ...