首页
壁纸
友链
留言
统计
个人导航
Search
1
一款超炫酷超好看的个人主页
889 阅读
2
网站顶部添加滚动文字
784 阅读
3
博客底部添加炫酷菜单栏
569 阅读
4
海南特产-鹧鸪茶
505 阅读
5
QQ和微信内置浏览器缓存清理
490 阅读
编程技术
Vue
JavaSe
Java
数据库
网站部署优化
typecho
超炫源码
超炫软件
实用技能
好东西
登录
Search
标签搜索
JavaSe
Vue
typecho
HTML标签
滚动文字
域名
申诉
表单校验
Nginx
java
HTML
flex布局
图片
服务器
登录框
组件传值
路由
缓存清理
鹧鸪茶
JavaScript
罗小黑
累计撰写
43
篇文章
累计收到
112
条评论
今日撰写
0
篇文章
首页
栏目
编程技术
Vue
JavaSe
Java
数据库
网站部署优化
typecho
超炫源码
超炫软件
实用技能
好东西
页面
壁纸
友链
留言
统计
个人导航
用户登录
登录
:欢迎您的到来! 如果您遇到任何问题,请联系博主qq:
180181332
搜索到
14
篇与
JavaSe
的结果
2021-11-05
Java面向对象(上)-2.类的结构(属性和方法)
Java面向对象(上)-类的结构(属性和方法)一、设计类,其实就是设计类的成员属性 = 成员变量 = field = 域、字段方法 = 成员方法 = 函数 = method创建类的对象 = 类的实例化 = 实例化类二、类和对象的使用(面向对象思想落地的实现):1.创建类,设计类的成员2.创建类的对象3.通过“对象.属性”或“对象.方法”调用对象的结构三、如果创建了一个类的多个对象,则每个对象都独立的拥有一套类的属性。(非static的)意味着:如果我们修改一个对象的属性a,则不影响另外一个对象属性a的值。四、对象的内存解析 //测试类 public class PersonTest { public static void main(String[] args) { //2. 创建Person类的对象 Person p1 = new Person(); //Scanner scanner = new Scanner(System.in); //调用对象的结构:属性、方法 //调用属性:“对象.属性” p1.name = "Tom"; p1.isMale = true; System.out.println(p1.name); //调用方法:“对象.方法” p1.eat(); p1.sleep(); p1.talk("Chinese"); //******************************* Person p2 = new Person(); System.out.println(p2.name);//null System.out.println(p2.isMale); //******************************* //将p1变量保存的对象地址值赋给p3,导致p1和p3指向了堆空间中的同一个对象实体。 Person p3 = p1; System.out.println(p3.name);//Tom p3.age = 10; System.out.println(p1.age);//10 } } //1.创建类,设计类的成员 class Person{ //属性 String name; int age = 1; boolean isMale; //方法 public void eat(){ System.out.println("人可以吃饭"); } public void sleep(){ System.out.println("人可以睡觉"); } public void talk(String language){ System.out.println("人可以说话,使用的是:" + language); } }
2021年11月05日
79 阅读
0 评论
0 点赞
2021-11-05
Java面向对象(上)-1.面向对象和面向过程的区别
Java面向对象(上)-面向对象和面向过程的区别一、Java面向对象学习的三条主线:(第4-6章)1.Java类及类的成员:属性、方法、构造器;代码块、内部类2.面向对象的三大特征:封装性、继承性、多态性、(抽象性)3.其它关键字:this、super、static、final、abstract、interface、package、import等“大处着眼,小处着手”二、“人把大象装进冰箱”1.面向过程:强调的是功能行为,以函数为最小单位,考虑怎么做。① 把冰箱门打开② 抬起大象,塞进冰箱② 把冰箱门关闭2.面向对象:强调具备了功能的对象,以类/对象为最小单位,考虑谁来做。 /* 人{ 打开(冰箱){ 冰箱.开开(); } 抬起(大象){ 大象.进入(冰箱); } 关闭(冰箱){ 冰箱.闭合(); } } 冰箱{ 开开(){} 闭合(){} } 大象{ 进入(冰箱){ } } * */ public class OOPTest { }三、面向对象的两个要素:类:对一类事物的描述,是抽象的、概念上的定义对象:是实际存在的该类事物的每个个体,因而也称为实例(instance)面向对象程序设计的重点是类的设计设计类,就是设计类的成员。
2021年11月05日
136 阅读
0 评论
0 点赞
2021-11-03
Java面向对象(上)-对象数组练习题
Java面向对象(上)-对象数组题目对象数组题目:定义类Student,包含三个属性:学号number(int),年级state(int),成绩score(int)。 创建20个学生对象,学号为1到20,年级和成绩都由随机数确定。问题一:打印出3年级(state值为3)的学生信息。问题二:使用冒泡排序按学生成绩排序,并遍历所有学生信息提示:1) 生成随机数:Math.random(),返回值类型double; 2) 四舍五入取整:Math.round(double d),返回值类型long。 public class StudentTest { public static void main(String[] args) { // Student s1 = new Student(); // Student s1 = new Student(); // Student s1 = new Student(); // Student s1 = new Student(); // Student s1 = new Student(); // Student s1 = new Student(); //声明Student类型的数组 Student[] stus = new Student[20]; //String[] arr = new String[10]; for(int i = 0;i < stus.length;i++){ //给数组元素赋值 stus[i] = new Student(); //给Student对象的属性赋值 stus[i].number = (i + 1); //年级:[1,6] stus[i].state = (int)(Math.random() * (6 - 1 + 1) + 1); //成绩:[0,100] stus[i].score = (int)(Math.random() * (100 - 0 + 1)); } //遍历学生数组 for(int i = 0;i <stus.length;i++){ // System.out.println(stus[i].number + "," + stus[i].state // + "," + stus[i].score); System.out.println(stus[i].info()); } System.out.println("********************"); //问题一:打印出3年级(state值为3)的学生信息。 for(int i = 0;i <stus.length;i++){ if(stus[i].state == 3){ System.out.println(stus[i].info()); } } System.out.println("********************"); //问题二:使用冒泡排序按学生成绩排序,并遍历所有学生信息 for(int i = 0;i < stus.length - 1;i++){ for(int j = 0;j < stus.length - 1 - i;j++){ if(stus[j].score > stus[j + 1].score){ //如果需要换序,交换的是数组的元素:Student对象!!! Student temp = stus[j]; stus[j] = stus[j + 1]; stus[j + 1] = temp; } } } //遍历学生数组 for(int i = 0;i <stus.length;i++){ System.out.println(stus[i].info()); } } } class Student{ int number;//学号 int state;//年级 int score;//成绩 //显示学生信息的方法 public String info(){ return "学号:" + number + ",年级:" + state + ",成绩:" + score; } }
2021年11月03日
143 阅读
0 评论
0 点赞
2021-10-28
Java基本语法-11.break和continue的使用
Java基本语法-break和continue的使用break和continue关键字的使用: 使用范围循环中使用的作用(不同点)相同点break:switch-case循环结构中结束当前循环关键字后面不能声明执行语句continue循环结构中结束当次循环关键字后面不能声明执行语句class BreakContinueTest { public static void main(String[] args) { for(int i = 1;i <= 10;i++){ if(i % 4 == 0){ break;//123 //continue;//123567910 //System.out.println("今晚迪丽热巴要约我!!!"); } System.out.print(i); } System.out.println("\n"); //****************************** label:for(int i = 1;i <= 4;i++){ for(int j = 1;j <= 10;j++){ if(j % 4 == 0){ //break;//默认跳出包裹此关键字最近的一层循环。 //continue; //break label;//结束指定标识的一层循环结构 continue label;//结束指定标识的一层循环结构当次循环 } System.out.print(j); } System.out.println(); } } }
2021年10月28日
70 阅读
0 评论
1 点赞
2021-10-28
Java基本语法-10.嵌套循环的使用
Java基本语法-嵌套循环的使用嵌套循环的使用1.嵌套循环:将一个循环结构A声明在另一个循环结构B的循环体中,就构成了嵌套循环2.外层循环:循环结构B内层循环:循环结构A说明① 内层循环结构遍历一遍,只相当于外层循环循环体执行了一次② 假设外层循环需要执行m次,内层循环需要执行n次。此时内层循环的循环体一共执行了m * n次技巧: 外层循环控制行数,内层循环控制列数class ForForTest { public static void main(String[] args) { //****** //System.out.println("******"); for(int i = 1;i <= 6;i++){ System.out.print('*'); } System.out.println("\n"); /* ****** ****** ****** ****** */ for(int j = 1;j <= 4;j++ ){ for(int i = 1;i <= 6;i++){ System.out.print('*'); } System.out.println(); } /* i(行号) j(*的个数) * 1 1 ** 2 2 *** 3 3 **** 4 4 ***** 5 5 */ for(int i = 1;i <= 5;i++){//控制行数 for(int j = 1;j <= i;j++){//控制列数 System.out.print("*"); } System.out.println(); } /* i(行号) j(*的个数) 规律:i + j = 5 换句话说:j = 5 - i; **** 1 4 *** 2 3 ** 3 2 * 4 1 */ for(int i = 1;i <= 4;i++){ for(int j = 1;j <= 5 - i;j++){ System.out.print("*"); } System.out.println(); } /* * ** *** **** ***** **** *** ** * */ //略 /* ----* ---* * --* * * -* * * * * * * * * * * * * * * * * * * */ //上半部分 //下半部分 } }
2021年10月28日
56 阅读
0 评论
1 点赞
2021-10-28
Java基本语法-9.do-while循环的使用
Java基本语法-do-while循环的使用do-while循环的使用一、循环结构的4个要素① 初始化条件② 循环条件 --->是boolean类型③ 循环体④ 迭代条件二、do-while循环结构:①do{③; ④; }while(②);执行过程:① - ③ - ④ - ② - ③ - ④ - ... - ②说明:1.do-while循环至少会执行一次循环体!2.开发中,使用for和while更多一些。较少使用do-whileclass DoWhileTest { public static void main(String[] args) { //遍历100以内的偶数,并计算所有偶数的和及偶数的个数 int num = 1; int sum = 0;//记录总和 int count = 0;//记录个数 do{ if(num % 2 == 0){ System.out.println(num); sum += num; count++; } num++; }while(num <= 100); System.out.println("总和为:" + sum); System.out.println("个数为:" + count); //*************体会do-while至少执行一次循环体*************** int number1 = 10; while(number1 > 10){ System.out.println("hello:while"); number1--; } int number2 = 10; do{ System.out.println("hello:do-while"); number2--; }while(number2 > 10); } }
2021年10月28日
43 阅读
0 评论
0 点赞
2021-10-28
Java基本语法-8.while循环的使用
Java基本语法-while循环的使用While 循环的使用一、循环结构的4个要素① 初始化条件② 循环条件 --->是boolean类型③ 循环体④ 迭代条件二、while循环的结构①while(②){③; ④;}执行过程:① - ② - ③ - ④ - ② - ③ - ④ - ... - ②说明:1.写while循环千万小心不要丢了迭代条件。一旦丢了,就可能导致死循环!2.我们写程序,要避免出现死循环。3.for循环和while循环是可以相互转换的! 区别:for循环和while循环的初始化条件部分的作用范围不同。算法:有限性。class WhileTest{ public static void main(String[] args) { //遍历100以内的所有偶数 int i = 1; while(i <= 100){ if(i % 2 == 0){ System.out.println(i); } i++; } //出了while循环以后,仍可以调用。 System.out.println(i);//101 } }
2021年10月28日
21 阅读
0 评论
0 点赞
1
2