// 最大公约数和最小公倍数
import java.util.Scanner;
public class Java1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入正整数n");
if(sc.hasNext());
int n = sc.nextInt();
System.out.println("请输入正整数m");
if(sc.hasNext());
int m = sc.nextInt();
for(int i = Math.max(m,n); i<=m*n;i++){
if((i % m == 0)&&(i % n == 0)){
System.out.println("两数最小公倍数: " +i);
break;
}
}
for(int j = Math.min(m, n); j>=1; j--){
if((m%j == 0)&&(n%j ==0)){
System.out.println("两数最大公约数:" +j);
break;
}
}
}
import java.util.Scanner;
public class Java1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入正整数n");
if(sc.hasNext());
int n = sc.nextInt();
System.out.println("请输入正整数m");
if(sc.hasNext());
int m = sc.nextInt();
for(int i = Math.max(m,n); i<=m*n;i++){
if((i % m == 0)&&(i % n == 0)){
System.out.println("两数最小公倍数: " +i);
break;
}
}
for(int j = Math.min(m, n); j>=1; j--){
if((m%j == 0)&&(n%j ==0)){
System.out.println("两数最大公约数:" +j);
break;
}
}
}
}
package src;
// 百鸡百钱问题:
public class Java2 {
public static void main(String[] args) {
for(int x = 1; x <= 20; x++){
for(int y =1; y <= 33; y++){
for(int r = 1; r <=100; r++){
if((5 * x + 3 * y + r / 3 == 100)&&( x+ y+ r== 100)&&r%3 == 0){
System.out.printf("公鸡%d\n母鸡%d\n小鸡%d\n\n" , x, y, r );
}
}
}
}
}
素数做出来运行只能算出四个怎么回事,骆老
public class Java3 {
public static void main(String[] args) {
for(int x=1; x<=100; x++){
int sum = 0;
for(int y=2; y<= x ; y++){
if(x % y==0){
sum++;
}
}
if(sum==2){
System.out.println(x+"是素数" );
sum=0;
}
}
}
}