C语言趣味程序(不到)百例 之Java实现
package zzq.main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
/************************************************************************
* C语言趣味程序(不到)百例-之Java实现
*
* 0 骨头找了其中比较简单的用Java实现了
*
* 1 他们完全可单独为篇,但骨头懒,所有题一并发了。
*
* 2 解法并非最优,多数用的穷举法。
*
* 3 原题可通过方法注释的题号查询PDF文档。再次为懒道歉
*
* 4 只做到83题,原因:1这几天忙2后面的需要思考3晚上需要搞艺术没时间
*
* @author lazybone 2010-05-14
*
************************************************************************/
public class JavaFun {
public static void main(String[] args) {
long start = System.currentTimeMillis();
new JavaFun().KaBuLieKe83(3976, 0);
long over = System.currentTimeMillis();
System.out.println("Cost:" + (over - start) + " ms.");
}
/**
* 83。卡布列克常数,挺好玩,实现一下
*/
public void KaBuLieKe83(int n, int count) {
int cha = getTheMaxOrMin(n, 1) - getTheMaxOrMin(n, 0);
System.out.println(count + ":" + getTheMaxOrMin(n, 1) + "-"
+ getTheMaxOrMin(n, 0) + " = " + cha);
count++;
if (n == 6174) {
System.out.println("I did it 6174");
} else {
KaBuLieKe83(cha, count);
}
}
/**
* 80.奇数平方和(和后面几个)根本无法得到验证,只能在有限范围内证明正确罢了
*
* 没有思考价值纯粹列等式。故跳过。
*/
/**
* 79。随机数求π圆周率
*/
public void getPaiByRandom79() {
double all = 10000000;
double l = 1000000;
double pai = 0;
double in = 0;
double x = 0, y = 0;
for (int i = 0; i < all; i++) {
x = (Math.random() * l);
y = (Math.random() * l);
if (x * x + y * y < l * l)
in++;
}
pai = (in / all * 4);
System.out.println("Times/All=" + in + "/" + all + " pai~=" + pai);
}
/**
* 76.小明买书
*
* 输出7.9+7.2时会出现小尾巴,原因不明,现在断网暂不深究
*/
public voi
相关文档:
public class JavaPlus {
public static void main(String[] args) {
int x = 5;
x++;// x = x + 1;//后加加
System.out.println(x);
x--;// x = x - 1;//后减减
System.out.println(x);
++x;// x = x + 1;//前加加
Sys ......
import java.awt.*;
import java.awt.event.*;
//俄罗斯方块类
public class ERS_Block extends Frame{
public static boolean isPlay=false;
public static int level=1,score=0;
public static TextField scoreField,levelField;
public static MyTimer timer;
Ga ......
对枚举类型印象大多来自于C
语言,在
C
语言中,枚举类型是一个
HardCode
(硬编码)类型,其使用价值并不大。因此,在
Java 5
之前,枚举是被抛弃的。然而
Java 5
以后的发现版本开始对枚举进行支持,枚举的引入给
Java
世界带来了争议。
笔者比较赞同引入枚举,作为一门通用的静态编程语言,应该是 ......
/**
* 把文本编码为Html代码
* @param target
* @return 编码后的字符串
*/
public static String htmEncode(String target)
{
StringBuffer stringbuffer = new StringBuffer();
int j = target.length();
for (int i = 0; i < j; i++)
......
result love(boy, girl)
{
if( boy.有房() and boy.有车() )
{
boy.set(nothing);
return girl.嫁给(boy);
&n ......