求5个C或Java的好源码,要是自己自创的,不要在哪里抄来?
发布网友
发布时间:2023-11-22 03:54
我来回答
共3个回答
热心网友
时间:2024-11-23 13:57
正好早上写了几个java小程序,就写几个吧,都是比较简单的哦
1.乘法口诀表
public class Chengfa {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + i * j + "\t");
}
System.out.print("\n");
}
}
}
2. 2/1+3/2+5/3+8/5+...
public class Chufa {
public static void main(String args[]) {
double[] a = new double[20];
double[] b = new double[20];
double result = 0;
a[0] = 2;
a[1] = 3;
b[0] = 1;
b[1] = 2;
result += a[0] / b[0];
result += a[1] / b[1];
for (int i = 2; i < 20; i++) {
a[i] = a[i - 1] + a[i - 2];
b[i] = b[i - 1] + b[i - 2];
result += a[i] / b[i];
}
System.out.println(result);
}
}
3.1000内的水仙花数(153=1^3+5^3+3^3)
public class Shuixianhua {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a, b, c;
for (int i = 100; i < 1000; i++) {
a = i / 100;
b = (i - a * 100) / 10;
c = (i - a * 100) - b * 10;
if (a * a * a + b * b * b + c * c * c == i) {
System.out.print(i + "\t");
}
}
}
}
4.最大公约数,最小公倍数
public class Gong {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Gong g = new Gong();
g.suan(36, 24);
}
public void suan(int a, int b) {
if (a > b) {
for (int i = a;; i++) {
if (i % a == 0 && i % b == 0) {
System.out.println(a + "和" + b + "的最小公倍数是" + i);
break;
}
}
for (int i = b;; i--) {
if (a % i == 0 && b % i == 0) {
System.out.println(a + "和" + b + "的最大公约数是" + i);
break;
}
}
} else {
for (int i = b;; i++) {
if (i % a == 0 && i % b == 0) {
System.out.println(a + "和" + b + "的最小公倍数是" + i);
break;
}
}
for (int i = a;; i--) {
if (a % i == 0 && b % i == 0) {
System.out.println(a + "和" + b + "的最大公约数是" + i);
break;
}
}
}
}
}
5.Fibonacci数列(1,1,2,3,5,8...)
public class Fibo {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Fibo f = new Fibo();
System.out.println(f.doFibo(23));
}
public int doFibo(int n) {
int[] a = new int[n];
int t = 2;
if (n == 1 || n == 2) {
a[n - 1] = 1;
} else {
a[0] = 1;
a[1] = 1;
System.out.print(a[0] + "\t" + a[1] + "\t");
for (int i = 2; i < n; i++) {
a[i] = a[i - 1] + a[i - 2];
System.out.print(a[i] + "\t");
t++;
if (t % 10 == 0) {
System.out.print("\n");
}
}
}
System.out.print("\n");
return a[n - 1];
}
}
五个了,都是自己写的,望采纳~
热心网友
时间:2024-11-23 13:57
去开源中国找把
热心网友
时间:2024-11-23 13:58
楼主,这个要求虽然不高,但恐怕很难满足你的需要