方案案例网站,大连网红打卡地,电子商务网站建设要求,网上开店铺需要什么流程#x1f36c; 博主介绍#x1f468;#x1f393; 博主介绍#xff1a;大家好#xff0c;我是 hacker-routing #xff0c;很高兴认识大家~
✨主攻领域#xff1a;【渗透领域】【应急响应】 【Java】 【VulnHub靶场复现】【面试分析】
#x1f389;点赞➕评论➕收藏 … 博主介绍 博主介绍大家好我是 hacker-routing 很高兴认识大家~
✨主攻领域【渗透领域】【应急响应】 【Java】 【VulnHub靶场复现】【面试分析】
点赞➕评论➕收藏 养成习惯一键三连
欢迎关注一起学习一起讨论⭐️一起进步文末有彩蛋
作者水平有限欢迎各位大佬指点相互学习进步目录 获取Integer对象的方式
在以前包装类如何进行计算
总结
Integer 成员方法
使用字符串进行进制转换
键盘录入使用nextLine 获取Integer对象的方式 public class demon1 {public static void main(String[] args) {/*public Integer(int value) 根据传递的整数创建一个Integer对象public Integer(String s) 根据传递的字符串创建一个Integer对象public static Integer valueOf(int i) 根据传递的整数创建一个Integer对象public static Integer valueof(String s) 根据传递的字符串创建一个Integer对象public static Integer valueof(String s, int radix) 根据传递的字符串和进制创建一个Integer对象*///1、利用构造方法获取intege的对象(jdk5以前)Integer i1 new Integer(1);Integer i2 new Integer(2);System.out.println(i1);System.out.println(i2);//2、利用静态方法获取integer的对象jdk5以前Integer i3 new Integer(123);Integer i4 new Integer(123);Integer i5 Integer.valueOf(123,8);System.out.println(i3);System.out.println(i4);System.out.println(i5);//3.这两种方式获取对象的区别(掌握)//底层原理//因为在实际开发中-128~127之间的数据用的比较多。//如果每次使用都是new对象那么太浪费内存了//所以提前把这个范围之内的每一个数据都创建好对象//如果要用到了不会创建新的而是返回已经创建好的对象。Integer i6 Integer.valueOf(127);Integer i7 Integer.valueOf(127);System.out.println(i6 i7);//trueInteger i8 Integer.valueOf(128);Integer i9 Integer.valueOf(128);System.out.println(i8 i9);//false//因为看到了new关键字在Java中每一次new都是创建了一个新的对象//所以下面的两个对象都是new出来地址值不一样。/*Integer i10 new Integer(127);Integer i11 new Integer(127);System.out.println(i10 i11);Integer i12 new Integer(128);Integer i13 new Integer(128);System.out.println(i12 i13);*/}
} 在以前包装类如何进行计算
public class demon1 {public static void main(String[] args) {//在以前包装类如何进行计算Integer i1 new Integer(1);Integer i2 new Integer(2);//需求:要把两个数据进行相加得到结果3//对象之间是不能直接进行计算的。//步骤://1.把对象进行拆箱变成基本数据类型//2.相加//3.把得到的结果再次进行装箱(再变回包装类)int result i1.intValue() i2.intValue();Integer i3 new Integer(result);System.out.println(i3);}
} package com.itheima.a03integerdemo;public class A03_IntegerDemo3 {public static void main(String[] args) {//在JDK5的时候提出了一个机制:自动装箱和自动拆箱//自动装箱:把基本数据类型会自动的变成其对应的包装类//自动拆箱:把包装类自动的变成其对象的基本数据类型//在底层此时还会去自动调用静态方法valueof得到一个Integer对象只不过这个动作不需要我们自己去操作了//自动装箱的动作//Integer i1 10;//Integer i2 new Integer(10);//自动拆箱的动作//int i i2;//结论在JDK5以后int和Integer可以看做是同一个东西因为在内部可以自动转化。}
}
总结 1.什么是包装类? 基本数据类型对应的对象 2.JDK5以后对包装类新增了什么特性? 自动装箱、自动拆箱 3.我们以后如何获取包装类对象? 不需要new不需要调用方法直接赋值即可
Integer i 10;Integer i1 10;
Integer i2 10;
Integer i3 i1 i2;Integer 成员方法 使用字符串进行进制转换
public class demon1 {public static void main(String[] args) {/*public static string tobinarystring(int i) 得到二进制public static string tooctalstring(int i) 得到八进制public static string toHexstring(int i) 得到十六进制public static int parseInt(string s) 将字符串类型的整数转成int类型的整数*///1、把整数转成二进制十六进制String str1 Integer.toBinaryString(100);System.out.println(str1);//2、把整数转成八进制String str2 Integer.toOctalString(100);System.out.println(str2);//3、把整数转化成十六进制String str3 Integer.toHexString(100);System.out.println(str3);//4.将字符串类型的整数转成int类型的整数//强类型语言:每种数据在java中都有各自的数据类型//在计算的时候如果不是同一种数据类型是无法直接计算的。int i Integer.parseInt(123);System.out.println(i);System.out.println(i 123);//246//细节1://在类型转换的时候括号中的参数只能是数字不能是其他否则代码会报错//细节2://8种包装类当中除了Character都有对应的parseXxx的方法进行类型转换String str true;boolean b Boolean.parseBoolean(str);System.out.println(b);}
} 键盘录入使用nextLine
import java.util.Scanner;public class demon1 {public static void main(String[] args) {//键盘录入Scanner sc new Scanner(System.in);System.out.println(请输入一个字符串);/* String str sc.next();System.out.println(str);*///弊端://当我们在使用nextnextIntnextDouble在接收数据的时候遇到空格回车制表符的时候就停止了//键盘录入的是123 123 那么此时只能接收到空格前面的数据//我想要的是接收一整行数据//约定://以后我们如果想要键盘录入不管什么类型统一使用nextLine//特点:遇到回车才停止String line sc.nextLine();System.out.println(line);double v Double.parseDouble(line);System.out.println(v);}
}