zoukankan      html  css  js  c++  java
  • 考试题1

    编写一个方法method(),判断一个数能否同时被3和5整除

    编写方法method

    public class test{
       public static void main(String[] args){ 
        
      }
      public static boolean method(){
      }
    }

    在子方法里判断是否能被3和5整除

    public class test {
        public static void main(String args[]){
        
        }
        
        public static boolean method(int x){
            if(x%3==0 && x%5==0){
                return true;
            }else{
                return false;
            }
            
        }
    }
    

    在主方法里定义一个变量接收这个返回值

    public class test {
        public static void main(String args[]){
               boolean y=method;
        }
        
        public static boolean method(int x){
            if(x%3==0 && x%5==0){
                return true;
            }else{
                return false;
            }
            
        }
    }
    

    输出 在主方法里传参数

    public class test {
        public static void main(String args[]){
            boolean y=method(15);
            System.out.println("这个数字"+(y==true? "能":"不能")+"被整除");
        }
        
        public static boolean method(int x){
            if(x%3==0 && x%5==0){
                return true;
            }else{
                return false;
            }
            
        }
    }
    

    运行结果:

      

  • 相关阅读:
    Java-LockSupport
    Kafka Eagle 安装
    Kafka shell
    python pip 使用
    Kafka 集群部署
    Kafka 概述
    DockerFile 简单使用
    《深入理解Java虚拟机》读书笔记
    linux安装redis
    Java多线程基础知识例子
  • 原文地址:https://www.cnblogs.com/zyn0216/p/7501888.html
Copyright © 2011-2022 走看看