今天用IDEA来试写一下java代码,界面确实不错,不过要适应一下新IDE
1.UTF-8是国际通用编码,其英文占一个字节,中文占三个字节,而GBK怎是国内的一种编码格式,其中中英文均占两个字节
2.数组的创建
a.数组如果只申明数组长度的话,则个数据类型的初始值如下图所示
byte[] byteArray = new byte[1];char[] charArray = new char[1];int[] intArray = new int[1];long[] longArray = new long[1];float[] floatArray = new float[1];double[] doubleArray = new double[1];String[] stringArray = new String[1];//initial valueSystem.out.println("byte默认类型为:" + byteArray[0]);//0System.out.println("char默认类型为:" + charArray[0]);// System.out.println("int默认类型为:" + intArray[0]);//0System.out.println("long默认类型为:" + longArray[0]);//0System.out.println("float默认类型为:" + floatArray[0]);//0.0System.out.println("string默认类型为:" + stringArray[0]);//null
b.数组的两种创方式
int[] a1 = new int[2];a1[0] = 1;a1[1] = 2; int[] a2 = {10, 22, 3, 4, 52};
还是推荐第二种
c.关于foreach
java的foreach的形式为for(数据类型 变量名:数组名),如果不是用数组的索引来进行遍历的话,变量的数据类型要与数组保持一致,如下图所示
public class Verify {public static void main(String[] args) {//单一数据类型数组遍历输出float[] a1 = {1.2f, 2.3f, 4.4f, 7.6f, 9.1f};for (float fl : a1) {System.out.print(fl + " ");}System.out.println("n");//String类型的数组String[] a2 = {"1", "2.3", "nihao", "a"};for (String str1 : a2) {System.out.print(str1 + " ");}System.out.println("n");//以数组的索引来遍历数组double[] a3 = {1.2, 2.2, 3.1, 4.5, 5.3};for (int i = 0; i < a3.length; i++) {System.out.print(a3[i] + " ");}} }
d.数组的复制
重点理解复制和被复制数组之间的关系
public class PracArrayCopy {public static void main(String[] args){int[] a1={1,2,3};int[] a2={4,5,6};/*直接用"="可以将数组数据进行覆盖改变后a1和a2指向同一个数组并且任意一个数组进行数组数据修改,另一个数组的元素也随之变化*/a1=a2;for(int x:a1){System.out.println(x);}a1[0]=100;a1[2]=66;for(int x:a2){System.out.println(x);}} }
今天无意间发现IDEA这个IDE工具,界面比eclipse好看多了,不过第一天上手,略显生疏,后期加强使用.明后两天双休,真是大福利啊,看来以后得找个双休的工作才行了,哈哈,洗澡睡觉
转载于:.html
本文发布于:2024-01-31 17:55:27,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170669492930318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |