day1016

package com.lovo;
/**
 * 最大公约数和最小公倍数
 *  @author 文波
 *
 */
import java.util.Scanner;

public class Test08 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入数N:");
        int n = sc.nextInt();
        System.out.print("请输入数M:");
        int m = sc.nextInt();
        int temp, gongyue = 0;
        if (n > m){
            temp =  m;
            m = n;
            n = temp;
        }
        for (int i = 1; i <= n; i++){
            if (n % i == 0 && m % i ==0){
                gongyue= i;
            }
        }
        System.out.println("最大公约数为:" + gongyue);
        System.out.println("最大公倍数为:" + m*n/gongyue );
    }

}
package day;
/**
 * 100内的素数
 * @author 文波
 *
 */
public class Text9 {
    public static void main(String[] args) {
        System.out.print("素数有:");

        for (int i = 2; i <= 100; i++){
            int count = 1;
            for (int j = 2; j <= i/2 ; j++){
                if (i % j == 0){
                    count = 0;
                    break;
                }
            }
            if (count == 1){
                System.out.printf("%d  ", i);
            }

        }
    }
}
package day;
/**
 * 百钱买鸡
 * @author 文波
 *
 */
public class Test10 {
    public static void main(String[] args) {
        int gongji, muji, xiaoji;
        for (gongji = 0; gongji <= 20; gongji++){
            for (muji = 0; muji <= 33; muji++){
                xiaoji = 100 - gongji - muji;
                if (xiaoji % 3 == 0 && 5 * gongji + 3 * muji + xiaoji / 3 == 100 ){
                    System.out.printf("公鸡为:%d只\t母鸡为:%d只\t小鸡为:%d只\n", gongji, muji, xiaoji);
                }
            }

        }

    }

}
时间: 2024-10-11 19:47:40

day1016的相关文章