文章列表
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
*@authorleno
*单子模式,保证在整个应用期间只加载一次配置属性文件
*/
public class Singleton {
private static Singleton instance;
priva ...
- 2009-04-15 21:14
- 浏览 1030
- 评论(0)
/**
*拷贝一个目录或者文件到指定路径下
*@paramsource
*@paramtarget
*/
public void copy(File source,File target) {
File tarpath = new File(target,source.getName());
if(source.isDirectory()) {
tarpath.mkdir();
File[] dir = source.listFiles();
...
- 2009-04-15 21:12
- 浏览 1020
- 评论(0)
/**
*@authorleno
*账户类
*默认有余额,可以取款
*/
class Account {
private float balance = 1000;
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance = balance;
}
/**
*取款的方法需要同步
*@par ...
- 2009-04-15 21:09
- 浏览 2035
- 评论(0)
/**
*@authorleno
*售票类
*/
class SaleTicket implements Runnable {
int tickets = 100;
public void run() {
while (tickets > 0) {
sale();
//或者下面这样实现
// synchronized (this) {
// if (tickets > 0) {
// System.out.print ...
- 2009-04-15 21:07
- 浏览 2372
- 评论(0)
class Producer implements Runnable {
private SyncStack stack;
public Producer(SyncStack stack) {
this.stack = stack;
}
public void run() {
for (int i = 0; i < stack.getProducts().length; i++) {
String product = "产品"+i;
stack.pu ...
- 2009-04-15 21:05
- 浏览 763
- 评论(0)
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.net.ServerSocket;
import java.net.Socket;
class Student implements Serializable {
private int sno;
private String sname;
...
- 2009-04-15 21:03
- 浏览 934
- 评论(0)
/**
*二分查找特定整数在整型数组中的位置(递归)
*@paramdataset
*@paramdata
*@parambeginIndex
*@paramendIndex
*@returnindex
*/
public int binarySearch(int[] dataset,int data,int beginIndex,int endIndex) {
int midIndex = (beginIndex+endIndex)/2;
if(data < ...
- 2009-04-15 21:00
- 浏览 816
- 评论(0)
/**
*获得任意一个整数的阶乘
*@paramn
*@returnn!
*/
public int factorial(int n) {
//递归
if(n==1) {
return 1;
}
return n*factorial(n-1);
//非递归
// int multi = 1;
// for (int i = 2; i <= n; i++) {
// multi*=i;
...
- 2009-04-15 20:59
- 浏览 864
- 评论(0)
/*将某个日期以固定格式转化成字符串
*@paramdate
*@returnstr
*/
public String dateToStr(java.util.Date date) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = sdf.format(date);
return str;
}
- 2009-04-15 20:56
- 浏览 884
- 评论(0)
import java.applet.*;
import java.awt.*;
import java.math.*;
public class drawsin extends Applet{
public void paint(Graphics g){
for(int x=100;x<300;x++) {
g.drawLine(x-100, (int)(50*Math.sin(x/31.4))+100, x-100, (int)(50*Math.sin(x/31.4)+100));
...
- 2009-04-15 20:31
- 浏览 744
- 评论(0)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SinTest extends JFrame {
double a=100;
double b=100.0;
////double c=10.0;
public SinTest() {
getContentPane().setLayout(new BorderLayout());
displayPanel.setBackground(Color.gray);
drawPanel=new Dra ...
- 2009-04-15 20:27
- 浏览 829
- 评论(0)
方法一:
public class T {
public static void main(String orgs[]) {
int size = 5;
for (int i = -size; i <= size; i++) {
System.out.println();
for (int j = -size; j <= size; j++) {
if (Math.abs(j) > size - Math.abs(i))
...
- 2009-04-14 23:26
- 浏览 715
- 评论(0)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class jisuanqi extends JFrame {
JTextField tf = new JTextField();
JPanel p = new JPanel();
double a = 0;
String s, str;
JButton b0 = new JButton("0");
JButton b1 = new JButton("1");
J ...
- 2009-04-14 23:22
- 浏览 658
- 评论(0)
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
...
- 2009-04-14 23:21
- 浏览 984
- 评论(0)
public class Prime {
int i = 100;
int num ;
public static boolean isPrime(int num) {
for(int j=2; j<=Math.sqrt(num); j++) {
if(num%j == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
for(int k=2; k<=100; k++) {
if(isPri ...
- 2009-04-14 23:19
- 浏览 618
- 评论(0)