10/14

第一题:

 

 

package ben.com;

public class Demo01 {
    public static Double sum(int num1,Double num2){
        Double sum=num1+num2;
        return sum;
    }
    
    public static String sum1(int num1,Double num2){

        if (num1==num2) {
            return "相等";
        }else {
            return "不相等";
        }
        
    }
    public static Double sum2(int num1,Double num2){

        if (num1>num2) {
            return (double)num1;
        }else if(num1<num2){
            return (double)num2;
        }else {
            return null;
        }
        
    }
    
    public static Object sum3(int num1,int num3){


        if (num1>num3) {
            return num3;
        }else if(num1<num3){
            return num1;
        }else {
            return null;
        }
    }
    

    public static void main(String[] args) {
        int num1=2;
        Double num2=12.0;
        int num3=1;
        System.out.println("和是:"+sum(num1, num2));
        System.out.println("两个数:"+sum1(num1, num2));
        System.out.println("较大的值:"+sum2(num1, num2));
        System.out.println("较小的值:"+sum3(num1, num3));
    }

}
第二题:
public class Demo02 {
    static int zhouchang(int chang,int kuan){
        
        return (chang+kuan)*2;
    }
    
static int mianji(int chang,int kuan){
        
        return chang*kuan;
    }
static Double zhouchang1(Double banjing){
    Double ret=banjing*2*3.14;
    return ret;
}
static Double mianji1(Double banjing){
    
    Double ret=banjing*banjing*3.14;
    return ret;
}

public static void main(String[] args) {
    int chang=5;
    int kuan=3;
    Double banjing=1.5;
    System.out.println("长方形周长是:"+zhouchang(chang, kuan));
    System.out.println("长方形面积是:"+mianji(chang, kuan));
    System.out.println("圆的周长是:"+zhouchang1(banjing));
    System.out.println("圆的面积是:"+mianji1(banjing));
}
}
第三题:
public class Demo03 {
    static boolean isSXH(int num){
        int ge=num%10;
        int shi=num/10%10;
        int bai=num/100;
        if (num==ge*ge*ge+shi*shi*shi+bai*bai*bai) {
            return true;
        }else {
            return false;
        }
        
        
    }
public static void main(String[] args) {
    int geshu=0;
     for (int i = 100; i <= 999; i++) {
        if (isSXH(i)==true&&geshu%2==0) {
            System.out.print(i+" ");
            geshu++;
        }else if (isSXH(i)==true&&geshu%2!=0) {
            System.out.println(i );
            geshu++;
        }
    }
     System.out.println("总个数:"+geshu);
}
}
复制代码
第四题:
 
package ben.com;

public class Demo04 {
    static void hello(int n){
        for (int i = 0; i < n; i++) {
            System.out.println("HelloWorld");
        }
    }
    
public static void main(String[] args) {
    int n=6;
    hello(n);
}
}
复制代码
第五题:
 
package ben.com;

public class Demo05 {
    static boolean isZHeng(int i){
        if (i%2==0) {
            return true;
        }else {
            return false;
        }
        
        
    }
public static void main(String[] args) {
    int sum=0;
    for (int i = 1; i <= 100; i++) {
        if (isZHeng(i)==true) {
            System.out.println(i);
            sum+=i;
        }
        
    }
    System.out.println("总和是:"+sum);
}
}
posted @ 2020-10-15 14:42  歪歪//  阅读(95)  评论(0编辑  收藏  举报