我是新手,刚学java
求1-100能被3整除,但不能被5整除的个数。然后输出符合的数字。Thanks!

解决方案 »

  1.   

    public class Test {
    public static void main(String[] args) {
    for(int i=3; i<=100; i=i+3) {
    if(i%5!=0) {
    System.out.print(i+" ");
    }
    }
    }
    }
      

  2.   

    public class Test {
    public static void main(String[] args) {
    for(int i=3; i<=100; i=i+3) {
    if(i%5!=0) {
    System.out.print(i+" ");
    }
    }
    }
    }
      

  3.   

    向这种算法有很多,看你怎么算了,
    一楼的算法简单明了,下面也是一种很简单的算法:public class Test{
         public static void main(String []args){
              for(int i = 1 ; i <= 100 ; i++){
                 if(i % 5 != 0 && i % 3 == 0){
                       System.out.println("第" + i + "数能被3整除不能被5整除:"+i);
                 }
              }
         }
    }
      

  4.   

    向这种算法有很多,看你怎么算了,
    一楼的算法简单明了,下面也是一种很简单的算法:public class Test{
         public static void main(String []args){
              for(int i = 1 ; i <= 100 ; i++){
                 if(i % 5 != 0 && i % 3 == 0){
                       System.out.println("第" + i + "数能被3整除不能被5整除:"+i);
                 }
              }
         }
    }
      

  5.   

    呵呵,楼主其实不一定就是为了要解决这里的这个简单的算法吧,
    我想最重要的还是基础性 的东西,
    也就是判断,循环,
    这里也就是java的基础内容了,我想,了解了这些基本的东西之后,你也会写出比这个更复杂一些的程序,可以用常人思维来看,你就用笔来画下来,怎么才能得到这个结构,然后一个过程就显然的很清晰在你的面前了,
    程序也就相当简单了。
      

  6.   

    1楼 的挺好的
    完整的应该这样
    public class LittleMath { /**
     * @param args
     */
    //求1-100能被3整除,但不能被5整除的个数。然后输出符合的数字
    public static void main(String[] args) {
            int count = 0;
    for(int i=3; i<=100; i=i+3) {
                if(i%5!=0) {
                    System.out.print(i+" ");
                    count++;
                }
            }
    System.out.println();
    System.out.println(count);
        }
    }
      

  7.   


    嗯,老师写的也差不多这样~Thanks!
      

  8.   

    for(int i=1;i<=100;i++)
    {
       if((i%3==0)&&(i%5!=0)
       System.out.println(i);
    }
      

  9.   

    public class Test {
        public static void main(String[] args) {
            for(int i=3; i<=100; i+=3) {
                if(i%5!=0) {
                    System.out.print(i+" ");
                }
            }
        }
    }
    这样比1楼更效率一些。哈哈
      

  10.   

    Pay attention to the requirement,we cannot find the count.