习题
买飞机票
求单个质数
求101-200的质数个数,并且打印出来
package com.java.two.demo; public class reduOnenum { public static void main(String[] args) { //判断一个数是否是质数 // int i = 101 ; int count = 0 ; for (int i = 101; i <200; i++) { boolean flag = true; for (int j = 2; j < i; j++) { if(i % j == 0){ flag = false; break; } } if (flag){ System.out.println(i+"是质数"); count++; } } System.out.println(count); } }
方法抽取
ctrl+alt+M
分清外循环与内循环的关系,其分别做的事情是什么
验证码开发
vecode
package com.java.two.demo; import java.util.Random; //验证码开发 public class veCode { public static void main(String[] args) { char[] chs = new char[52]; //a-Z存进chs[] for (int i = 0; i < chs.length; i++) { if (i<26) //ASCII chs[i]=(char) (97+i); else chs[i]=(char) (65+i-26); } // //遍历a-Z // for (int j = 0; j < chs.length; j++) { // System.out.println(chs[j]); // } String re = ""; Random r = new Random(); for (int i = 0; i < 4; i++) { int chindex = r.nextInt(chs.length); re= re + chs[chindex]; } int num =r.nextInt(10); re = re +num; System.out.println(re); } }
copy数组
int[] arr1={1,2,3,4,5}; int[] brr=new int[arr1.length]; for (int i = 0; i < arr1.length; i++) { brr[i]=arr1[i]; } for (int i = 0; i < brr.length; i++) { System.out.println(brr[i]); }
求数组max
选中后shift+f6:批量修改
数字加密
2.1
上图结果:54321,错!
上图结果:12345,正确
抢红包
优化
抽奖
int redCount=0;
面向对象