(1)
public class {
public static void main(String[] args) {
int startPosition = 0, endPosition = 0;
char cStart = 'a', cEnd = 'я';
startPosition = (int) cStart;
endPosition = (int) cEnd;
System.out.println("俄文字母表:");
for (int i = startPosition; i <= endPosition; i++) {
char c = '\0';
c = (char) i;//i做char 型转换运算,并将结果赋值给c
System.out.println("" + c);
if ((i - startPosition + 1) % 10 == 0)
System.out.println("");
}
}
}
(2)
public class {
public static void main ( String args []) {
double sum = 0, a = 1;
int i = 1;
while (i<=20){
sum = sum + a;
i++;
a = a * i;
}
System.out.println("sum=" + sum);
}
}
(3)
public class {
public static void main(String args[]) {
int i, j;
for (j = 2; j <= 100; j++) {
for (i = 2; i <= j / 2; i++) {
if (j % i == 0)
break;
}
if (i > j / 2) {
System.out.print("" + j);
}
}
}
}
(4)
public class {
public static void main(String args[]) {
double sum = 0, a = 1, i = 1;
while (i <= 20) {
sum = sum + a;
i++;
a = (1.0 / i) * a;
}
System.out.println("使用while循环计算的sum=" + sum);
for (sum = 0, i = 1, a = 1; i <= 20; i++) {
a = a * (1.0 / i);
sum = sum + a;
}
System.out.println("使用for循环计算的sum=" + sum);
}
}
(5)
public class {
public static void main ( String args []) {
int sum = 0, i, j;
for (i = 1; i <= 1000; i++) {
for (j = 1, sum = 0; j < i; j++) {
if (i % j == 0)
sum = sum + j;
}
if (sum == i)
System.out.println("完数:" + i);
}
}
}
(6)
import java.util.Scanner;
public class {
public static void main(String[] args) {
System . out . println("请输人两个非零正整数,每输入一个数回车确认");
Scanner reader = new Scanner(System.in);
int m = 0, n = 0, temp = 0, gy = 0, gb = 0,a,b;
a = m = reader.nextInt();
b = n = reader.nextInt();
if(m<n) {
temp = m;
m = n;
n = temp;
}
int r = m%n;
while(r!=0) {
n = m;
m = r;
r = m % n;
}
gy = n;
gb = a*b/gy;
System . out . println ("最大公约数:"+gy);
System . out . println ("最小公倍数:"+gb);
}
}
(7)
public class {
public static void main(String args[]) {
int n = 1;
long sum = 0, t = 1;
t = n * t;
while (true) {
sum = sum + t;
if (sum > 9999)
break;
n++;
t = n * t;
}
System.out.println("满足条件的最大整数:" + (n - 1));
}
}