论坛: 编程破解 标题: JAVA>Anything 复制本贴地址    
作者: zhanjiajun [zhanjiajun]    论坛用户   登录

能不能贴出一断自己收藏的源码,最经典的算法和理解。什么语言都好,共同进步是网络的原创精神。


今天到一家公司应聘,他们是用JAVA的,我从来没有接触过,不过,听哪个人的叙述,他们是这样定义的:
一\按目前发展来看,J2EE将是主流语言,其它语言将被淘汰.
二\JAVA内容很难,非常难,不是我这种基础的可以上手的(我说我的算法基础还可以,他们笑着说,算法不管用!)
三\EJB\JSP\JB,一串,他们数落着我如果要进公司,需要学习的东西.
四\他们公司很大,是企业级的开发,在业界是数一数二的.他们的中间件用IBM的WEB什么东东.
五\我说:我有面向对象开发的经验,也有一定面向对象的理念.他说:面向对象非常简单!JAVA才难.

面试我的是:人事部和技术部两个N?人!

我想问一下各位方家:
一\能不能说一下JAVA开发平台是什么东西.不知道怎么问,愿意说就说一下!
二\JAVA应该也是面向对象的语言吧,有类的机制和要领吗?
三\什么EJB,J2EE,在开发环境是什么样子喔?和VC\DELPHI的开发环境是不是有天壤之别?>?/

286,能给我一个具体的以下问题的源程序不?

2000年1月1日为周六.给出一个2000-2100年日历表,提示:闰年为能被2整除且不能被100整除,或能被400整除.

我是这样子做的:
在子函数jud_model(int year)中得到当年的当月之前的天数.如2050年11月.则计算2050是否为闰年,如果为闰年,则判断月份是否大于2,大于2,则返回:月份*30-1,否则返回:月份*30;如果不是闰年,则返回:月份*30.

if((i mod 2)==0 and (i mod 100!=0)  or (i mod 400)==0 )
.......


定义了  year_day month_day now_day 三个变量.
用一个循环:

year_day为用户输入年份,count 为计数器,计算闰年的年数:

for(i=2000;i< year_day;i++)
{  if((i mod 2)==0 and (i mod 100!=0)  or (i mod 400)==0 ) count++;}


然后count_day=(year_day-count)*365+count*364+jud_model(int year);

然后:用(count_day-2)/7得当前月历的第一号的周几.


我的算法错误太多,请方家一定耐心看完.教我一下,最好是给出一个完整,带算法解释的源程序.我愿意用一个色情网站密码换呀!!!!!如果是纯洁人士,我愿意为唱赞歌!!!!


temp_datay

[此贴被 飘渺虚心(zhanjiajun) 在 07月21日19时13分 编辑过]


[此贴被 飘渺虚心(zhanjiajun) 在 07月23日15时20分 编辑过]

地主 发表时间: 05-07-21 18:55

回复: 286 [unique]   版主   登录
1 如果你对JAVA一点不懂,而他们又是招JAVA开发的,建议你学好后再去应聘。否则绝不是你拿一个程序让他们看看就行的。

2 应聘你的人所说的很片面,不可全信。他说的象是在JAVA的广告。

3 2000年1月1日为周六.给出一个2000-2100年日历表,提示:闰年为能被2整除且不能被100整除,或能被400整除.
这个应该不难。但现在没时间去作。你到网上查查吗,应该很多。


B1层 发表时间: 05-07-22 10:58

回复: xiaoqing09 [xiaoqing09]   论坛用户   登录
import java.util.Calendar;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Hashtable;
public class CalendarPad extends JFrame implements MouseListener
{
  int year,month,day;
  Hashtable hashtable;           
  File file;                     
  JTextField showDay[];           
  JLabel title[];                 
  Calendar 日历;
  int 星期几;
  NotePad notepad=null;           
  Month 负责改变月;
  Year  负责改变年;
  String 星期[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
  JPanel leftPanel,rightPanel;   
  public  CalendarPad(int year,int month,int day)
  {
    leftPanel=new JPanel();
    JPanel leftCenter=new JPanel();
    JPanel leftNorth=new JPanel();
    leftCenter.setLayout(new GridLayout(7,7)); 
                                                 
    rightPanel=new JPanel();
    this.year=year;
    this.month=month;
    this.day=day;
    负责改变年=new Year(this);
    负责改变年.setYear(year);
    负责改变月=new Month(this);
    负责改变月.setMonth(month);
 
    title=new JLabel[7];                       
    showDay=new JTextField[42];                 
    for(int j=0;j<7;j++)                       
      {
        title[j]=new JLabel();
        title[j].setText(星期[j]);
        title[j].setBorder(BorderFactory.createRaisedBevelBorder());
        leftCenter.add(title[j]);
      }
    title[0].setForeground(Color.red);
    title[6].setForeground(Color.blue);

    for(int i=0;i<42;i++)                       
      {
        showDay[i]=new JTextField();
        showDay[i].addMouseListener(this);
        showDay[i].setEditable(false);
        leftCenter.add(showDay[i]);
      }
       
    日历=Calendar.getInstance();
    Box box=Box.createHorizontalBox();         
    box.add(负责改变年);
    box.add(负责改变月);
    leftNorth.add(box);
    leftPanel.setLayout(new BorderLayout());
    leftPanel.add(leftNorth,BorderLayout.NORTH);
    leftPanel.add(leftCenter,BorderLayout.CENTER);
    leftPanel.add(new Label("请在年份输入框输入所查年份(负数表示公元前),并回车确定"),
                  BorderLayout.SOUTH) ;
    leftPanel.validate();
    Container con=getContentPane();
    JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
                                    leftPanel,rightPanel);
   
    con.add(split,BorderLayout.CENTER);
    con.validate();
   
    hashtable=new Hashtable();
    file=new File("日历记事本.txt");
      if(!file.exists())
      {
      try{
          FileOutputStream out=new FileOutputStream(file);
          ObjectOutputStream objectOut=new ObjectOutputStream(out);
          objectOut.writeObject(hashtable);
          objectOut.close();
          out.close();
          }
      catch(IOException e)
          {
          }
      }
   
    notepad=new NotePad(this);                                     
    rightPanel.add(notepad);
   
    设置日历牌(year,month);
    addWindowListener(new WindowAdapter()
                    { public void windowClosing(WindowEvent e)
                      {
                        System.exit(0);
                      }
                    });
    setVisible(true);
    setBounds(100,50,524,285);
    validate();
  }
  public void 设置日历牌(int year,int month)
  {
    日历.set(year,month-1,1);             
   
    星期几=日历.get(Calendar.DAY_OF_WEEK)-1;
    if(month==1||month==2||month==3||month==5||month==7
                        ||month==8||month==10||month==12)
        {
            排列号码(星期几,31);       
        }
    else if(month==4||month==6||month==9||month==11)
        {
            排列号码(星期几,30);
        }
    else if(month==2)
        {
        if((year%4==0&&year%100!=0)||(year%400==0)) 
          {
            排列号码(星期几,29);
          }
        else
          {
            排列号码(星期几,28);
          }
      }
  }
  public void 排列号码(int 星期几,int 月天数)
  {
      for(int i=星期几,n=1;i<星期几+月天数;i++)
            {
              showDay[i].setText(""+n);
              if(n==day)
                {
                  showDay[i].setForeground(Color.green);
                  showDay[i].setFont(new Font("TimesRoman",Font.BOLD,20));
                }
              else
                {
                  showDay[i].setFont(new Font("TimesRoman",Font.BOLD,12));
                  showDay[i].setForeground(Color.black);
                }
              if(i%7==6)
                {
                  showDay[i].setForeground(Color.blue); 
                }
              if(i%7==0)
                {
                  showDay[i].setForeground(Color.red); 
                }
              n++;
            }
      for(int i=0;i<星期几;i++)
            {
                showDay[i].setText("");
            }
      for(int i=星期几+月天数;i<42;i++)
            {
                showDay[i].setText("");
            }
  }
public int getYear()
  {
    return year;
  }
public void setYear(int y)
  {
    year=y;
    notepad.setYear(year);
  }
public int getMonth()
  {
    return month;
  }
public void setMonth(int m)
  {
    month=m;
    notepad.setMonth(month);
  }
public int getDay()
  {
    return day;
  }
public void setDay(int d)
  {
    day=d;
    notepad.setDay(day);
  }
public Hashtable getHashtable()
  {
    return hashtable;
  }
public File getFile()
  {
    return file;
  }
public void mousePressed(MouseEvent e)           
  {
    JTextField source=(JTextField)e.getSource();
    try{
        day=Integer.parseInt(source.getText());
        notepad.setDay(day);
        notepad.设置信息条(year,month,day);
        notepad.设置文本区(null);
        notepad.获取日志内容(year,month,day);
        }
      catch(Exception ee)
        {
        }
  }
public void mouseClicked(MouseEvent e)
  {
  }
public void mouseReleased(MouseEvent e)
  {
  }
public void mouseEntered(MouseEvent e)
  {
  }
public void mouseExited(MouseEvent e)
  {
  }

public static void main(String args[])
  {
      Calendar calendar=Calendar.getInstance();   
      int y=calendar.get(Calendar.YEAR);         
      int m=calendar.get(Calendar.MONTH)+1;       
      int d=calendar.get(Calendar.DAY_OF_MONTH);
      new CalendarPad(y,m,d);
  }

----------------------------------------------------------------------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Month extends Box implements ActionListener
{
  int month;                         
  JTextField showMonth=null;         
  JButton 下月,上月;
  CalendarPad 日历;
  public Month(CalendarPad 日历)
  { 
    super(BoxLayout.X_AXIS);       
    this.日历=日历;
    showMonth=new JTextField(2);
    month=日历.getMonth();
    showMonth.setEditable(false);
    showMonth.setForeground(Color.blue);
    showMonth.setFont(new Font("TimesRomn",Font.BOLD,16));
    下月=new JButton("下月");
    上月=new JButton("上月");
    add(上月);
    add(showMonth);
    add(下月);
    上月.addActionListener(this);
    下月.addActionListener(this);
    showMonth.setText(""+month);
  }
public void setMonth(int month)
  {
    if(month<=12&&month>=1)
      {
      this.month=month;
      }
    else
      {
        this.month=1;
      }
    showMonth.setText(""+month);
  }
public int getMonth()
  {
    return month;
  }
public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==上月)
      {
        if(month>=2)
        {
            month=month-1;
            日历.setMonth(month);
            日历.设置日历牌(日历.getYear(),month);
        }
        else if(month==1)
        {
            month=12;
            日历.setMonth(month);
            日历.设置日历牌(日历.getYear(),month);
        }
      showMonth.setText(""+month);
      }
    else if(e.getSource()==下月)
      {
        if(month<12)
          {
            month=month+1;
            日历.setMonth(month);
            日历.设置日历牌(日历.getYear(),month);
          }
        else if(month==12)
          {
            month=1;
            日历.setMonth(month);
            日历.设置日历牌(日历.getYear(),month);
          }
        showMonth.setText(""+month);
      }
  } 
}
--------------------------------------------------------------------------------------import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Year extends Box implements ActionListener
{
  int year;                         
  JTextField showYear=null;         
  JButton 明年,去年;
  CalendarPad 日历;
  public Year(CalendarPad 日历)
  { 
    super(BoxLayout.X_AXIS);       
    showYear=new JTextField(4);
    showYear.setForeground(Color.blue);
    showYear.setFont(new Font("TimesRomn",Font.BOLD,14));
    this.日历=日历;
    year=日历.getYear();
    明年=new JButton("下年");
    去年=new JButton("上年");
    add(去年);
    add(showYear);
    add(明年);
    showYear.addActionListener(this);
    去年.addActionListener(this);
    明年.addActionListener(this);
  }
public void setYear(int year)
  {
    this.year=year;
    showYear.setText(""+year);
  }
public int getYear()
  {
    return year;
  }
public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==去年)
      {
        year=year-1;
        showYear.setText(""+year);
        日历.setYear(year);
        日历.设置日历牌(year,日历.getMonth());
      }
    else if(e.getSource()==明年)
      {
        year=year+1;
        showYear.setText(""+year);
        日历.setYear(year);
        日历.设置日历牌(year,日历.getMonth());
      }
    else if(e.getSource()==showYear)
      {
        try
            {
              year=Integer.parseInt(showYear.getText());
              showYear.setText(""+year);
              日历.setYear(year);
              日历.设置日历牌(year,日历.getMonth());
            }
        catch(NumberFormatException ee)
            {
              showYear.setText(""+year);
              日历.setYear(year);
              日历.设置日历牌(year,日历.getMonth());
            }
      }
  } 
}
-----------------------------------------------------------------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;

public class NotePad extends JPanel implements ActionListener
{
  JTextArea text;             
  JButton 保存日志,删除日志;
  Hashtable table;           
  JLabel 信息条;             
  int year,month,day;         
  File file;                 
  CalendarPad calendar;
  public  NotePad(CalendarPad calendar)
  {
    this.calendar=calendar;
    year=calendar.getYear();
    month=calendar.getMonth();
    day=calendar.getDay();;
    table=calendar.getHashtable();
    file=calendar.getFile();
    信息条=new JLabel(""+year+"年"+month+"月"+day+"日",JLabel.CENTER);
    信息条.setFont(new Font("TimesRoman",Font.BOLD,16));
    信息条.setForeground(Color.blue);
    text=new JTextArea(10,10);
    保存日志=new JButton("保存日志") ;
    删除日志=new JButton("删除日志") ;
    保存日志.addActionListener(this);
    删除日志.addActionListener(this);
    setLayout(new BorderLayout());
    JPanel pSouth=new JPanel();     
    add(信息条,BorderLayout.NORTH);
    pSouth.add(保存日志);
    pSouth.add(删除日志);
    add(pSouth,BorderLayout.SOUTH);
    add(new JScrollPane(text),BorderLayout.CENTER);
  }
public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==保存日志)
      {
        保存日志(year,month,day);
      }
    else if(e.getSource()==删除日志)
      {
      删除日志(year,month,day);
      }
  }
  public void setYear(int year)
  {
    this.year=year;
  }
public int getYear()
  {
    return year;
  }
public void setMonth(int month)
  {
    this.month=month;
  }
  public int getMonth()
  {
    return month;
  }
  public void setDay(int day)
  {
    this.day=day;
  }
  public int getDay()
  {
    return day;
  }
public void 设置信息条(int year,int month,int day)
  {
    信息条.setText(""+year+"年"+month+"月"+day+"日");
  }
  public void 设置文本区(String s)
  {
    text.setText(s);
  }
  public void 获取日志内容(int year,int month,int day)
  {
      String key=""+year+""+month+""+day;
      try
            {
              FileInputStream  inOne=new FileInputStream(file);
              ObjectInputStream inTwo=new ObjectInputStream(inOne);
              table=(Hashtable)inTwo.readObject();       
              inOne.close();
              inTwo.close();
            }
      catch(Exception ee)
            {
            }
      if(table.containsKey(key))
          {
            String m=""+year+"年"+month+"月"+day+"这一天有日志记载,想看吗?";
            int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
                                              JOptionPane.QUESTION_MESSAGE);
                if(ok==JOptionPane.YES_OPTION)
                  {
                    text.setText((String)table.get(key));
                  }
                else
                  {
                  text.setText("");
                  }
          }
      else
          {
            text.setText("无记录");
          }
  }
  public void 保存日志(int year,int month,int day)
  {
    String 日志内容=text.getText();
        String key=""+year+""+month+""+day;
       
        String m=""+year+"年"+month+"月"+day+"保存日志吗?";
        int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
                                              JOptionPane.QUESTION_MESSAGE);
        if(ok==JOptionPane.YES_OPTION)
          {
          try
            {
              FileInputStream  inOne=new FileInputStream(file);
              ObjectInputStream inTwo=new ObjectInputStream(inOne);
              table=(Hashtable)inTwo.readObject();
              inOne.close();
              inTwo.close();
              table.put(key,日志内容);                                 
              FileOutputStream out=new FileOutputStream(file);
              ObjectOutputStream objectOut=new ObjectOutputStream(out);
              objectOut.writeObject(table);
              objectOut.close();
              out.close();
            }
          catch(Exception ee)
            {
            }
        }
  }
  public void 删除日志(int year,int month,int day)
  {
      String key=""+year+""+month+""+day;
        if(table.containsKey(key))
          { 
            String m="删除"+year+"年"+month+"月"+day+"日的日志吗?";
            int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
                                              JOptionPane.QUESTION_MESSAGE);
            if(ok==JOptionPane.YES_OPTION)
              {
              try
                {
                FileInputStream  inOne=new FileInputStream(file);
                ObjectInputStream inTwo=new ObjectInputStream(inOne);
                table=(Hashtable)inTwo.readObject();
                inOne.close();
                inTwo.close();
                table.remove(key);                                       
                FileOutputStream out=new FileOutputStream(file);
                ObjectOutputStream objectOut=new ObjectOutputStream(out);
                objectOut.writeObject(table);
                objectOut.close();
                out.close();
                text.setText(null);
                }
              catch(Exception ee)
                {
                }
              }
          }
        else
          {
           
            String m=""+year+"年"+month+"月"+day+"无日志记录";
            JOptionPane.showMessageDialog(this,m,"提示",JOptionPane.WARNING_MESSAGE);
          }
  }

}
----------------------------------------------------------------------------------
这是一个带日历的记事本程序源码 你参考一下
尤其是Month,Year类

B2层 发表时间: 05-07-22 14:04

回复: zhanjiajun [zhanjiajun]   论坛用户   登录
谢谢回答!但是能不能带点算法说明的?

我只是问问有没有.

B3层 发表时间: 05-07-22 18:54

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号