Java练习-day1(3)

5.编程输出1~100中能被3整除但不能被5整除的数,并统计有多少个这样的数

package com.Newclass.Study;
public class ClassWork5 {
 public static void main(String[] args) {
  int count = 0;
  for(int i=0;i<=100;i++){
   if(i % 3 == 0&&i % 5 != 0) {
    System.out.println(i);
    count  ++;
   }
  }
  System.out.println("个数为:"+count);
 }
}
输出结果为:3
6
9
12
18
21
24
27
33
36
39
42
48
51
54
57
63
66
69
72
78
81
84
87
93
96
99
个数为:27
6.打印出100-999之间所有的水仙花数, 例如:153是一个"水仙花数",
因为153=1的三次方+5的三次方+3的三次方
package com.Newclass.Study;
public class ClassWork6 {
 public static void main(String[] args) {
  for (int t=100;t<=999;t++){
    int a=t/100,b=(t%100)/10,c=(t%100)%10;
   if (t==a*a*a+b*b*b+c*c*c){
   System.out.println(t);
   }
  }
 }
}
输出结果为:153
370
371
407
7.1,2,3,4四个数字,看这四个数字能组成多少个且无重复数字的三位数?都是多少?
package com.Newclass.Study;
public class ClassWork7 {
 public static void main(String[] args) {
  int count =0;
  for(int a = 1;a < 5;a ++) {
   for(int b = 1;b < 5;b ++) {
    for(int c = 1;c < 5;c ++) {
     if(a != b && a != c && b !=c) {
     System.out.println(a * 100 + b * 10 + c);
     count ++;
     }
    }
   }
  }
  System.out.println("个数为" + count);
 }
 
}
输出结果为:123
124
132
134
142
143
213
214
231
234
241
243
312
314
321
324
341
342
412
413
421
423
431
432
个数为24
posted @ 2019-10-29 21:33  anfmj  阅读(111)  评论(0)    收藏  举报