摘要: public static void main(String[] args) { //判断一个数的奇偶性 check(5); } public static void check(int number){ if (number % 2 ==0){ System.out.println(number+ 阅读全文
posted @ 2022-01-13 18:50 wtws 阅读(37) 评论(0) 推荐(0)
摘要: System.out.println("1-5的和是:"+sum(5));}public static int sum (int n){ int sum =0; for (int i =1; i <=n; i++){ sum += i; } return sum;}; 阅读全文
posted @ 2022-01-13 18:44 wtws 阅读(49) 评论(0) 推荐(0)
摘要: 方法定义的完整格式: 修饰符 返回值类型 方法名(参数类型 参数名){ ... 方法体(需要执行的功能代码) ... return 返回值;} 方法常见问题 方法的编写顺序无所谓。 方法与方法之间是平级关系,不能嵌套定义。 方法的返回值类型为void(无返回值),方法内则不能使用return返回数据 阅读全文
posted @ 2022-01-09 20:47 wtws 阅读(53) 评论(0) 推荐(0)
摘要: //冒泡排序 //1.定义一个数组存储数据 int [] arr= {1, 2, 5, 0}; //2.定义一个循环控制比较轮数 for (int i = 0; i < arr.length -1; i++) { //3.定义一个循环控制比较的次数 for (int j = 0; j < arr.l 阅读全文
posted @ 2022-01-07 18:37 wtws 阅读(27) 评论(0) 推荐(0)
摘要: //键盘录入一组工号,最终随机输出一组出来作为排名 //1.动态初始化一个数组,存储5个工号 int[] codes= new int[5]; //2.定义循环,一次录入一个工号对应的位置 Scanner scanner= new Scanner(System.in); for (int i = 0 阅读全文
posted @ 2022-01-07 18:16 wtws 阅读(161) 评论(0) 推荐(0)
摘要: //5-20之间的随机数,让用户猜测,猜中输出该数据第一次在数组出现的索引 //1.定义一个动态初始化数组存储5个随机的1-20之间的数据 int[] data =new int[5]; //2.动态的生成5个随机的1-20之间的数据并存到数组 Random random =new Random() 阅读全文
posted @ 2022-01-06 20:37 wtws 阅读(85) 评论(0) 推荐(0)
摘要: 数组元素求最大值 //数组元素求最大值//1.定义数组int[] facescores ={15, 9000, 10000, 20000, 9500,-5};//2.定义一个变量存储最大值元素int max = facescores[0];//3.遍历数组的每个元素for (int i = 1; i 阅读全文
posted @ 2022-01-06 20:16 wtws 阅读(284) 评论(0) 推荐(0)
摘要: 数组元素的遍历 //数组元素的遍历 int[] arr = {12, 13, 14, 15, 16};​ //原始方式 System.out.println(arr[0]); System.out.println(arr[1]); System.out.println(arr[2]); System 阅读全文
posted @ 2022-01-06 20:06 wtws 阅读(456) 评论(0) 推荐(0)
摘要: 数组的元素默认值 byte、short、char、int、long、char类型定义的数组,初始化默认是0 类、接口、数组、String类型定义的数组,默认值是null float、double类型定义的数组,默认值是0.0 boolean类型定义的数组,默认值是false //初始化写法 // 数 阅读全文
posted @ 2022-01-06 19:48 wtws 阅读(185) 评论(0) 推荐(0)
摘要: 数组:用来存储一批同种类型的内存区域 数组变量名存储的是数组在内存中的地址,数组是引用类型。 数组的最大索引:最大长度减1 length-1 //数组: 数据类型 [] 数组名称 = new 数据类型[]{元素1,....}// 数据类型 [] 数组名称 = {元素1,....}//double [ 阅读全文
posted @ 2022-01-05 21:14 wtws 阅读(43) 评论(0) 推荐(0)