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的关键字 ...
随机推荐
- Anaconda安装及使用
前言 在Linux系统上一般会预安装python,但有时候版本过低,通过apt或yum无法安装较新的python版本,只能通过编译python源码进行安装.然而通过源码安装会依赖大量的库,手动安装这些 ...
- 浏览器开发者工具console
浏览器开发者工具基本使用教程 谷歌Chrome浏览器开发者工具教程-基础功能篇 - 算命de博客 - CSDN博客 JavaScript Console 对象 | 菜鸟教程
- 第六届SD省赛 Circle of Friends
Circle of Friends Time Limit: 2000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- Mac anaconda安装 “conda command not found” 解决方法
官网下载包直接安装的时候可能会产生这种问题,这主要还是环境变量配置的问题 一般我们添加环境变量的方法是编辑.bash_profile或.bashrc,在文件里插入下面这段代码 export PATH= ...
- [RPM,YUM]RHEL Centos mount local source / RHEL CentOS挂载本地源
RHEL: 使用YUM安装Oracle必要软件包,将操作系统ISO文件“rhel-server-6.5-x86_64.iso”分别上传至两个节点主机“/root”目录,以root用户登录,执行以下命令 ...
- spring 中的设计模式
https://mp.weixin.qq.com/s?__biz=MzU0MDEwMjgwNA==&mid=2247485205&idx=1&sn=63455d2313776d ...
- Nginx安装及使用
安装 设置安装位置 切换到root下安装:CentOS: #su root Ubuntu: #sudo su 切换文件夹: #cd /usr/local/src/ 安装编译环境 ububtu平台编 ...
- CC1310 笔记
GPIO控制: #include <ti/drivers/GPIO.h> GPIO_init() 函数会调用 结构体实例 GPIOCC26XX_config,把需要使用到的GPIO放一起, ...
- Lending Club—构建贷款违约预测模型
python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...
- CNN 激活函数
CNN: 1\ Siamoid 2\ Relu + Softplus 图片来源: http://ufldl.stanford.edu/tutorial/supervised/MultiLayerNeu ...