java code
yanxiazhiqiu
这个作者很懒,什么都没留下…
展开
-
100个人报数,数到10的人出圈
import java.io.*;class Person{ public int id; public boolean status=false; Person next; Person(int id){this.id=id;} void setStatus(){ status=true; } public void numAction(){ Game.M--原创 2005-09-30 16:53:00 · 2030 阅读 · 1 评论 -
求数组的众数(TestArray类应新的需求添加了一个功能)
/* output most times of occurence */ public static void timesTopN(int[] arr){ int l=arr.length; int[] times=new int[l]; Arrays.fill(times,1); for(int i=0;i fo原创 2005-12-01 15:22:00 · 885 阅读 · 1 评论 -
n人围成一圈报数,数到m的人出圈(据评论所写,谢谢zf)
package com.yatium;public class RePlay{ int key; int[] circle; public RePlay(int key,int size){ this.key=key; circle=new int[size]; for(int i=0;i } public void game原创 2005-11-15 09:56:00 · 876 阅读 · 0 评论 -
n人围成一圈报数,数到m的人出圈(据软件设计师教程上的思想编写)
package com.yatium;class Node{ int no; Node next; Node(int no){ this.no=no; next=null; }}class Circle{ int length; Node head; Circle(int length){ this.length=原创 2005-11-15 10:55:00 · 1036 阅读 · 1 评论 -
n天以后的日期
public static String afterNDay(int n){ Calendar c=Calendar.getInstance(); DateFormat df=new SimpleDateFormat("yyyy-MM-dd"); c.setTime(new Date()); c.add(Calendar.DAY_OF_MON原创 2005-11-15 08:55:00 · 663 阅读 · 0 评论 -
求数组的top n的下标,有缺点
/** * an fault : topN(int[],int) method will * change the value of the argument int[] * */package com.yatium;import java.util.*;public class TestArray{ /* exchange two element with given indexe原创 2005-11-02 16:03:00 · 826 阅读 · 0 评论 -
一个偶数等于两个素数之和
public class Test40{ public static boolean primeNum(int i){ for(int j=2;j if(i%j==0) return false; return true; } public static void main(String[] args) throws Except原创 2005-10-31 12:31:00 · 1252 阅读 · 0 评论 -
订单程序
public class UsesOrder{public static void main(String[] args){ Goods c1=new Coffee(2,4),c2=new Coffee(4,8),c3=new Cake(3,6),c4=new Cake(5,10); Order o1=new Order(c1,c3),o2=new Order(c2,c4); S原创 2005-10-26 11:22:00 · 599 阅读 · 0 评论 -
构造链表
import java.io.*;class StudentNode{ String name; int age; StudentNode next; public StudentNode(String name,int age){ this.name=name; this.age=age; next=null; }}publ原创 2005-10-14 16:27:00 · 559 阅读 · 0 评论 -
水仙花数
public class DaffodilNum{ private int n; public DaffodilNum(int n){ this.n=n; } public boolean IsOrNot(){ int a=n%10; int b=(n%100-a)/10; int c=(n-b*10-a)/100;原创 2005-10-28 12:15:00 · 704 阅读 · 1 评论 -
随机两位数
import java.util.*;public class Test28{ public static void main(String[] args){ int[] arr1=new int[10]; for(int i=0;i { int temp=(int)(Math.random()*100);原创 2005-10-26 11:19:00 · 898 阅读 · 0 评论 -
一个字符串在另一个字符串中匹配的次数
int MatchTimes(String sub,String s){ int len=sub.length(),count=0,offset=0; while(true) { int temp=s.indexOf(sub,offset); if(temp!=-1) { offset=temp+len;原创 2005-10-21 09:11:00 · 694 阅读 · 0 评论 -
组合公式(拿递归实现了一下,连这个都发,很无耻吧,哈哈!)
package com.yatium;/** * combination */public class Combination{ public static int comb(int n,int m){ if(m else if(m==n||n==0) return 1; else if(n==1) return m; els原创 2005-12-01 17:02:00 · 722 阅读 · 0 评论