码迷,mamicode.com
首页 > 其他好文 > 详细

day1016

时间:2014-10-16 23:21:53      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   java   for   sp   div   on   

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);
                }
            }
            
        }
        
    }

}

 

day1016

标签:style   blog   color   ar   java   for   sp   div   on   

原文地址:http://www.cnblogs.com/Barneyman/p/4029789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!