publicclass t12 {publicstaticvoidmain(String[] args){for(int i =1; i <=100; i++){int a = i %10;if(a ==3|| a ==5|| a ==7){continue;}System.out.println(i);}}}
4.键盘录入一个整数判断是否为质数
publicclass t13 {publicstaticvoidmain(String[] args){System.out.println("输入一个整数");int num =newScanner(System.in).nextInt();}publicstaticvoidshow(int num){if(num ==1){System.out.println("小子这个数"+ num +"不是质数");return;}}}
5.生成一个顺序数组,将这个数组的元素打乱顺序后输出
publicclass t14 {publicstaticvoidmain(String[] args){int[] array =newint[]{};
array =setArray();for(int i =0; i < array.length; i++){System.out.println(array[i]);}System.out.println("=================");shuffle(array);for(int i =0; i < array.length; i++){System.out.println(array[i]);}}publicstaticint[]setArray(){int[] a =newint[6];for(int i =0; i < a.length; i++){
a[i]= i+1;}return a;}publicstaticvoidshuffle(int[] array){/*
i循环遍历数组
随机定位下标j与i交换
*/for(int i =0; i < array.length; i++){int c =newRandom().nextInt(array.length);System.out.println(c);int t = array[i];
array[i]= array[c];
array[c]= t;}}}
6.接收用户输入的任意自然数,累计所有位数数字之和
publicclass t15 {publicstaticvoidmain(String[] args){System.out.println("请输入一个自然数:");int n =newScanner(System.in).nextInt();//定义求和变量int sum =0;//while循环获取每一位的数子while(n !=0){//求和累加
sum = sum +(n%10);//去掉一位数字,将下一位变为个位
n = n /10;}System.out.println("输入的自然数,每位数之和为:"+ sum);}}
7.求任意数组中所有元素的最大值
publicclass t16 {publicstaticvoidmain(String[] args){int[] arr ={100,20,30,66,999,10,3};//定义一个最大值int max = arr[arr.length-1];//遍历数组for(int i =0; i < arr.length; i++){if(arr[i]> max){//当前数组内所有数组进行比较,如果有大于max的则赋值给max
max = arr[i];}}System.out.println("最大值是:"+ max);}}