随笔分类 -  java

摘要:package lll; public class Test { public static void main(String[] args) { Circle c1=new Circle(); c1.radius=2; System.out.println(c1.findArea()); } } 阅读全文
posted @ 2022-01-06 15:55 ice--cream
摘要:方法:描述类应该具有的功能 方法的声明: 权限修饰符 返回值类型 方法名(形参列表){ ​ 方法体 ​ } 简单类示范: package lll; public class Test { public static void main(String[] args) { Person p1=new P 阅读全文
posted @ 2022-01-06 15:41 ice--cream
摘要:相同点 定义变量的格式相同,数据类型 变量名=变量值 先声明,后使用 都有其对应的作用域 不同点 在类中声明的位置不同 属性:直接定义在类的一对{}内 局部变量:声明在方法内、方法形参、代码块内、构造器形参、构造器内部的变量 关于权限修饰符的不同 属性:可以在声明属性时,指明其权限,使用权限修饰符。 阅读全文
posted @ 2022-01-06 12:31 ice--cream
摘要:属性:对应类中的成员变量 行为:对应类中的成员方法 package lll; public class Test { public static void main(String[] args) { Person p1=new Person(); p1.name="lll"; p1.age=11; 阅读全文
posted @ 2022-01-06 10:39 ice--cream
摘要:java.util.Arrays:操作数组的工具类,里面定义了很多操作数组的方法 判断两个数组是否相等 package lll; import java.util.Arrays; public class Test { public static void main(String[] args) { 阅读全文
posted @ 2022-01-05 20:57 ice--cream
摘要:package lll; public class Test { public static void main(String[] args) { int[] arr=new int[]{-11,-22,-3,0,23,2,4,6}; int temp=0; //需要执行多少轮 for(int i= 阅读全文
posted @ 2022-01-05 20:21 ice--cream
摘要:前提:所要查找的数组必须有序 package lll; public class Test { public static void main(String[] args) { int[] arr=new int[]{1,2,3,4,5,6,7,8,9,10}; //要查找的数 int dest=8 阅读全文
posted @ 2022-01-05 19:16 ice--cream
摘要:package lll; public class Test { public static void main(String[] args) { String[] str=new String[]{"aa","bb","cc","dd","ee"}; //要查找的字符串dest String de 阅读全文
posted @ 2022-01-05 17:48 ice--cream
摘要:package lll; public class Test { public static void main(String[] args) { int[] arr1=new int[]{1,2,3,4,5,6}; int temp=0; //方法一 for(int i=0;i<arr1.leng 阅读全文
posted @ 2022-01-05 17:32 ice--cream
摘要:JAVA 数组的复制 package lll; public class Test { public static void main(String[] args) { int[] arr1=new int[10]; int[] arr2; //给arr1赋值并打印 for(int i=0;i<ar 阅读全文
posted @ 2022-01-05 15:12 ice--cream
摘要:package lll; public class Test { public static void main(String[] args) { int[] arr=new int[10]; //随机赋值 for(int i=0;i<10;i++){ arr[i]=(int)(Math.rando 阅读全文
posted @ 2022-01-05 14:43 ice--cream
摘要:package lll; public class Test { public static void main(String[] args) { //声明一个二维数组 int[][] yangHui=new int[10][]; for(int i=0;i<yangHui.length;i++){ 阅读全文
posted @ 2022-01-05 14:16 ice--cream
摘要:JAVA 二维数组 二维数组的声明和初始化 package lll; import java.util.Scanner; public class Test { public static void main(String[] args) { //静态初始化1 int[][] num1=new in 阅读全文
posted @ 2022-01-04 20:48 ice--cream
摘要:package lll; import java.util.Scanner; public class Test { public static void main(String[] args) { System.out.print("请输入学生个数:"); Scanner scan=new Sca 阅读全文
posted @ 2022-01-04 17:32 ice--cream
摘要:一维数组的声明和初始化 package nkc_java; public class ArrayTest { public static void main(String[] args) { //一维数组的声明和初始化 int[] ids;//声明 //静态初始化 ids=new int[]{100 阅读全文
posted @ 2022-01-04 16:45 ice--cream
摘要:class Test{ public static void main(String[] args){ boolean isFlag=true; //获取当前时间距1970-1-1 00:00:00的毫秒数 long start=System.currentTimeMillis(); for(int 阅读全文
posted @ 2022-01-03 19:59 ice--cream
摘要:JAVA 带标签的break class Test1{ public static void main(String[] args){ label:for(int i=1;i<=10;i++){ for(int j=1;j<=10;j++){ if(j%3==0){ break label; } S 阅读全文
posted @ 2022-01-03 19:42 ice--cream
摘要:从键盘上输入year、month和day,要求通过程序输出该日期为该年的第几天 import java.util.Scanner; class Test{ public static void main(String[] args){ Scanner scan=new Scanner(System. 阅读全文
posted @ 2022-01-03 11:14 ice--cream
摘要:switch注意事项 switch结构中的表达式,只能是如下的6种数据类型之一: byte、short、char、int、枚举类型(JDK5.0新增)、String类型(JDK7.0新增) 阅读全文
posted @ 2022-01-03 10:41 ice--cream
摘要:JAVA基本语法-switch 要求用switch结构,判断学生是否及格,成绩大于60分的,输出“及格”,成绩低于60分的,输出“不及格”。 要求用switch结构,而成绩有0-100分共101种情况,看起来要写101个case,但那样太费力了,我们可以对学生的成绩进行一些处理,比如:将成绩除以10 阅读全文
posted @ 2022-01-03 09:39 ice--cream