|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
前言
毕业后在社会上历练了一段时间 深切感受到了社会的毒打
目前在一家上市公司做市场工作 感觉自己随时会被替代
还是手上有技术活的人饿不死 所以想把原来在鱼C学习的东西捡一捡
关于学习笔记 本来只想写在自己的本子上 可能是分享欲和话痨属性的加持
又找不到特定的人分享 即记述于fishc.bbs 希望自己能坚持下去
更希望有人能见证自己的成长!
内容提示:
自动类型转换:在JAVA进行赋值或运算时,精度小的类型自动转换为精度大的数据类型
数据类型 按 精度(容量) 排序 两条线不发生自动转换
char -> int -> long -> float -> double
byte -> short -> int -> long -> float -> double
char 、 byte 、 short 三个在进行运算时 会直接提升至 int
基本数据类型:一共8种 【所占字节】
1.数值型:
整数类型(byte【1】,short【2】,int【4】,long【8】)
浮点(小数)类型(float【4】,double【8】)
2.布尔型(boolean【1】),存放 true , false
3.字符型(char【2】),存放单个字符 ‘ a ’
1 byte = 8 bit (bit 是计算机最小单位 字节是最小基本单位)
一、学习内容
1、强制数据类型转换
- public class ForceConvert{
- public static void main(String[] args){
- //强制数据类型转换
- int n1 = (int)1.9;
- System.out.println("n1=" + n1);// 1 造成精度损失
- int a = 2000;
- byte b = (byte)a;
- System.out.println(a);//造成 数据溢出
- }
- }
复制代码
2、基本数据类型转换为字符串(String)
- public class StringToBasic{
- public static void main(String[] args){
- //基本数据类型 -> String 字符串
- int n1 = 100;
- float n2 = 1.1F;
- double n3 = 4.5;
- boolean n4 = true;
- String s1 = n1 + "";
- String s2 = n2 + "";
- String s3 = n3 + "";
- String s4 = n4 + "";
- System.out.println(s1 + " " + s2 + " " + s3 + " " + s4 + " ");
- //String 字符串 -> 基本数据类型
- String s5 = "123";
- //使用 基本数据类型 对应的 包装类 的相应 方法 得到 基本数据类型
- int num1 = Integer.parseInt(s5);
- float num2 = Float.parseFloat(s5);
- double num3 = Double.parseDouble(s5);
- long num4 = Long.parseLong(s5);
- System.out.println("============================");
- System.out.println(num1);
- System.out.println(num2);
- System.out.println(num3);
- System.out.println(num4);
- //字符串 转换 字符 char -> 含义是指把字符串的第一个字符取出
- //s5.charAt(1) -> 得到字符串 s5 的第一个字符 0 1 2 3
- System.out.println(s5.charAt(0));
- }
- }
复制代码
- public class StringToBasicDetail{
- public static void main(String[] args){
- //字符串不可以转换为整数int
- String str = "hello";
- int n1 = Integer.parseInt(str);
- System.out.println(n1);
- }
- }
复制代码
3、使用char类型,分别保存 \n \t \r \\ 1 2 3字符 并打印输出
- public class Homework2{
- public static void main(String[] args){
- //使用char类型,分别保存 \n \t \r \\ 1 2 3字符 并打印输出
- char c1 = '\n';//换行
- char c2 = '\t';//制表位
- char c3 = '\r';//回车
- char c4 = '\\';//输出\
- char c5 = '1';//
- char c6 = '2';//
- char c7 = '3';//
- System.out.println(c1);
- System.out.println(c2);
- System.out.println(c3);
- System.out.println(c4);
- System.out.println(c5);
- System.out.println(c6);
- System.out.println(c7);
- }
- }
复制代码
二、疑惑
三、感受
今天学的内容太少了,写一个程序就要回想之前的学习内容。
心态也特别浮躁 怎么也学不下去了 可能是昨天晚上没睡好
今天早点睡 明天多学点内容 明天学习运算符 内容还蛮多的
2022年9月28日22:06 |
|