找出100-1000之间能被5和6整除的数

能被5和6整除


import java.util.*;
class Main {
  public static void main(String[] args){
    int count = 0;
    for(int i = 100; i <= 1000; i++){
      if(i % 5 == 0 && i % 6 == 0){
        count++;
        System.out.print((count % 10 == 0) ? (i + "\t\n") : (i + "\t"));
        
      }
    }
  }
}

能被5或6整除,不能同时被两者整除,异或

import java.util.*;
class Main {
  public static void main(String[] args){
    int count = 0;
    for(int i = 100; i <= 200; i++){
      if(i % 5 == 0 ^ i % 6 == 0){
        count++;
        System.out.print((count % 10 == 0) ? (i + "\t\n") : (i + "\t"));
        
      }
    }
  }
}
posted @ 2022-05-24 16:43  Scenery_Shelley  阅读(241)  评论(0编辑  收藏  举报