1 输入两个自然数,找出两个数的最大公因数
import ;
public class zuida {
public static void main(String[] args) {
Scanner scanner = new Scanner();
("请输入第一个数字 ");
int num1 = ();
("请输入第2个数字 ");
int num2 = ();
int temp = num1;
num1 = num1 < num2? num1: num2;
num2 = temp > num2? temp: num2;
for(int num = num1; num >= 1; num--){
if(num1 % num == 0 && num2 % num == 0){
("最大公因数为 : " + num);
break;
}
}
}
}
2 接受输入x,计算sinx的近似值(不使用Math类中的函数,自己实现)
package Test;
import ;
public class sin {
static double stop = ;
public static void main(String[] args) {
sin s = new sin();
("The value of sin(30')");
(( / , 100));
}
double sin(double x, int n) {
double v = x;
int postive = 1;
for (int i = 1; i < 2 * n; i = i + 2) {
v = v + postive * ((x, i) / factorial(i));
postive = postive * -1;
}
return v;
}
private double factorial(double s) {
double r = 1;
for (int i = 1; i <= s; i++) {
r = r * i;
}
return r;
}
}
3 打印所有的水仙花数(一个三位数,各位的三次方之和等于它本身)
public class z
Java实验测试题目 来自淘豆网m.daumloan.com转载请标明出处.