题目1:import java.util.Scanner;
public class m1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print(“请依次输入a,b,c,d四个数:“);
int a, b, c, d;
double sum;
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
d = input.nextInt();
if (c – d == 0)
System.out.println(“error!”);
else {
sum = (a + b) / (c – d);
System.out.print(“(a+b)/(c-d)的结果是:“ + sum);
}
}
}
题目2:import java.util.Scanner;
public class m2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println(“依次输入身高,体重:“);
int BMI;
float high = input.nextFloat();
int weight = input.nextInt();
BMI = (int) (weight / (high * high));
if (BMI
System.out.println(“体重严重过轻!“);
else if (BMI > 16 && BMI
System.out.println(“体重过轻!“);
else if (BMI > 18 && BMI
System.out.println(“体重适中!“);
else if (BMI > 24 && BMI
System.out.println(“体重过重!“);
else if (BMI > 29 && BMI
System.out.println(“有点肥胖!“);
else if (BMI > 35)
System.out.println(“非常肥胖!“);
}
}
题目3:import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println(“请输入一个大于0小于100的数;“);
int n = input.nextInt();
int[] a = new int[100];
a[1] = a[2] = 1;
if (n >= 3) {
for (int i = 3; i <= n; i++) {
a[i] = a[i – 1] + a[i – 2];
}
}
for (int j = 1; j <= n; j++) {
System.out.print(a[j] + ” “);
}
}
}
题目4:public class PerfectNumber {
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int n = 1; n <= 1000; n++) {
int sum = 1;
for (int k = 2; k <= n / 2; k++) {
if (n % k == 0)
sum = sum + k;
}
if (sum == n)
System.out.println(n + “是一个完全因子“);
}
}
}
题目5:import java.util.Scanner;
public class PrimeFactor {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Scanner input = new Scanner(System.in);
System.out.println(“请输入一个正整数;“);
int n = input.nextInt();
do {
for (int k = 2; k <= n; k++) {
if (n % k == 0) {
System.out.print(k + ” “);
n = n / k;
break;
}
}
} while (n != 1);
}
}