package com.company;
//乘法口诀表
public class czh {
public static void main(String[] args) {
int a,b,c;
for (a = 1; a <= 9; a++) {
for (b = 1; b <= a; b++) {
c = a * b;
System.out.print(b + "*" + a + "=" + c + "\t");
}
System.out.println();
}
}
}
import java.util.Scanner;
//求最大公约数 最小公倍数
public class lz {
public static void main(String[] args) {
int x,y ,c,t;
System.out.println("请输入两个数:");
Scanner lmf = new Scanner(System.in);
x= lmf.nextInt();
y = lmf.nextInt();
if(x < y){
int temp = x;
x = y;
y = temp;
}
for (int i = x; i > 0; i++) {
if(i % x == 0 && i % y == 0){
System.out.println("最小公倍数:"+ i);
break;
}
}
while (x != y) //两个数不相等就一直循环
{
if (x > y) //此处举例 x=35 y=25
{
x = x - y;
//符合条件一 带入计算 x=10 此处x=10,但是x不等于y 所以将x=10继续返回while语句中计算
//此时已经符合y>x的条件 所以代入到else语句中得出y=5 此时 y仍然不等于x 所以 依然返回whil语句重新计算
//注 此时带入到while语句中的x y的值分别是 x=10,y=5.
//此时符合x>y的条件 代入计算 得出y=5 此时 xy的值已经相同 故输出结果
} else {
y = y - x;
}
}
package com.company.src;
public class wanshu {
public static void main(String[] args) {
int i;
for(i=2;i<1000;i++){
int sum=0;
for(int j=1;j<i;j++){
if(i%j==0){
sum=sum+j;//判断j是否为i的因子,将因子累加
}
}
if(sum==i){
System.out.println(i+"是完数!");
}
}
}
}
System.out.println("最大公约数:"+x);
}
}