`
yuyeyi
  • 浏览: 38144 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论
文章列表
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 ...
/** *拷贝一个目录或者文件到指定路径下 *@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(); ...
/** *@authorleno *账户类 *默认有余额,可以取款 */ class Account { private float balance = 1000; public float getBalance() { return balance; } public void setBalance(float balance) { this.balance = balance; } /** *取款的方法需要同步 *@par ...
/** *@authorleno *售票类 */ class SaleTicket implements Runnable { int tickets = 100; public void run() { while (tickets > 0) { sale(); //或者下面这样实现 // synchronized (this) { // if (tickets > 0) { // System.out.print ...
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 ...
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; ...
/** *二分查找特定整数在整型数组中的位置(递归) *@paramdataset *@paramdata *@parambeginIndex *@paramendIndex *@returnindex */ public int binarySearch(int[] dataset,int data,int beginIndex,int endIndex) { int midIndex = (beginIndex+endIndex)/2; if(data < ...
/** *获得任意一个整数的阶乘 *@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; ...
/*将某个日期以固定格式转化成字符串 *@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; }
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)); ...
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 ...
方法一: 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)) ...
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 ...

设置字体

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; ...

求素数

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 ...
Global site tag (gtag.js) - Google Analytics