首页 > 代码库 > day1016
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); } } } }}
day1016
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。