java吧 关注:1,253,797贴子:12,742,757

回复:【入驻JAVA吧 记录学习点滴】

取消只看楼主收藏回复

晚上用**做约瑟夫环的问题,有很多新收获,明天写上来,现在要断电了


312楼2012-01-05 22:54
回复
    代码虽然有点长,但是思路应该很清晰了
    这里开始出现的问题在第一个for循环的条件,开始写的是for(int i = 0; i < al.size(); i++),结果经过测试这样写是得不到结果滴。因为虽然在开始给**一个初始容量,但是并不是说**中元素的个数是20。
    可能也有不少初学者像我一样,把这个跟数组中的赋初始长度认为是一样的功能了。


    315楼2012-01-06 09:09
    回复
      集(和谐)合


      317楼2012-01-06 09:12
      回复
        蛋疼 最近发帖老是失败


        320楼2012-01-09 08:20
        回复
          算了 下次再试吧 贴代码无限失败


          323楼2012-01-09 08:23
          回复
            放假回家了~~感觉现在不想把什么都贴上来了~~~


            326楼2012-01-15 19:45
            回复
              import java.io.*;
              public class TestIOSpeed { public static void main(String[] args) throws IOException {
              //测试缓冲流复制文件的速度,借助System提供的nanoTime()方法,以毫微秒为单位
              long startTime1 = System.nanoTime();
              FileReader test1 = new FileReader("f:\\test1.txt");
              FileWriter test2 = new FileWriter("f:\\tets2.txt");
              int c1 = 0;
              while(-1 != (c1 = test1.read())){
              test2.write(c1);
              }
              test2.flush();
              long endTime1 = System.nanoTime();
              long time1 = endTime1 - startTime1;
              System.out.println(time1 + "毫微秒");
              //测试非缓冲流复制文件的速度
              long startTime2 = System.nanoTime();
              FileInputStream test3 = new FileInputStream("f:\\test3.txt");
              FileOutputStream test4 = new FileOutputStream("f:\\test4.txt");
              int c2 = 0;
              while(-1 != (c2 = test3.read())){
              test4.write(c2);
              }
              test4.flush();
              long endTime2 = System.nanoTime();
              long time2 = endTime2 - startTime2;
              System.out.println(time2 + "毫微秒");
              }
              }
              


              327楼2012-01-15 19:45
              回复
                结果为
                100935687毫微秒(缓冲流)
                686269568毫微秒


                328楼2012-01-15 19:46
                回复
                  不好意思写混了~~~这是字节式读写速度与字符式的读取


                  329楼2012-01-15 19:59
                  回复
                    而且是55kb的txt文档


                    330楼2012-01-15 20:02
                    回复
                      增加了一下代码测试一下ArrayList添加元素与取出元素的速度,多次运行证实,速度是差不多的
                      ArrayList<String> array1 = new ArrayList<String>();
                      String str1 = "beibei";
                      int i = 0;
                      long startTime3 = System.nanoTime();
                      //添加
                      while(i < size){
                      array1.add(str);
                      i++;
                      }
                      long endTime3 = System.nanoTime();
                      System.out.println(endTime3 - startTime3);
                      i = 0;
                      long startTime4 = System.nanoTime();
                      //取出
                      while(i < size){
                      array1.get(i);
                      i++;
                      }
                      long endTime4 = System.nanoTime();
                      System.out.println(endTime4 - startTime4);


                      333楼2012-01-15 20:36
                      回复
                        也就是说呢缓冲流数据,读与写的速度也相差不大


                        334楼2012-01-15 20:37
                        回复
                          import java.awt.*;
                          import java.awt.event.*;
                          import javax.swing.*;
                          public class CommenComponentTest {
                          // public static Label bulidLabel(){
                          // Label label = new Label();
                          // return label;
                          // } public static void main(String[] args) {
                          JFrame window = new JFrame("DNF装备找回申诉");
                          window.setBounds(500, 300, 700, 400);
                          window.setBackground(Color.magenta);
                          window.setLayout(null);
                          window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                          window.setVisible(true);
                          // JPanel panel = new JPanel();
                          // panel.setBounds(0, 0, 700, 400);
                          // panel.setBackground(Color.BLUE);
                          ImageIcon image = new ImageIcon("C:/Users/bm/Pictures/卡赞.jpg");
                          JLabel imgLabel = new JLabel(image);
                          imgLabel.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
                          window.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
                          //window.add(panel);
                          Container cp = window.getContentPane();
                          ((JPanel) cp).setOpaque(false);
                          Label label1 = new Label("服务器:");
                          label1.setBounds(150, 80, 120, 20);
                          Label label2 = new Label("希望恢复的角色:");
                          label2.setBounds(150, 110, 120, 20);
                          Label label3 = new Label("被盗前最后一次上号时间:");
                          label3.setBounds(150, 140, 140, 20);
                          Label label4 = new Label("发现被盗时间:");
                          label4.setBounds(150, 170, 120, 20);
                          final Choice choice1 = new Choice();
                          choice1.setBounds(300, 80, 100, 10);
                          final Choice choice2 = new Choice();
                          choice2.setBounds(300, 110, 100, 20); choice1.add("安徽一区");
                          choice1.add("安徽二区");
                          choice1.add("安徽三区");
                          choice1.add("江苏一区");
                          choice1.add("江苏二区");
                          choice1.add("江苏三区");
                          choice1.add("江苏四区");
                          choice1.add("江苏五区");
                          choice1.add("江苏六区");
                          choice1.addItemListener(new ItemListener(){
                          @Override
                          public void itemStateChanged(ItemEvent e) {
                          String str = choice1.getSelectedItem();
                          if(str == "安徽三区"){
                          choice2.removeAll();
                          choice2.add("beibei");
                          choice2.add("ceiond");
                          choice2.add("ddewf");
                          }
                          else if(str == "江苏五区"){
                          choice2.removeAll();
                          choice2.add("chen");
                          choice2.add("pop");
                          }
                          else{
                          choice2.removeAll();
                          }
                          }
                          });
                          TextField tf1 = new TextField();
                          tf1.setBounds(300, 140, 140, 20);
                          tf1.setEditable(true);
                          TextField tf2 = new TextField();
                          tf2.setBounds(300, 170, 140, 20);
                          tf2.setEditable(true);
                          window.add(label1);
                          window.add(label2);
                          window.add(label3);
                          window.add(label4);
                          window.add(choice1);
                          window.add(choice2);
                          window.add(tf1);
                          window.add(tf2);
                          }
                          }
                          


                          335楼2012-01-17 20:17
                          回复
                            将图片作为背景的方法: 将背景图放在标签里——将背景标签添加到jframe的LayeredPane面板里——创建内容面板——将内容面板设为透明,这样LayeredPane面板中的背景才能显示出来


                            336楼2012-01-17 20:22
                            回复
                              如上,运行结果相信很多人都问过,有时候有,有时候没有~~就这样````好累~~暂时不想百度


                              338楼2012-01-17 22:07
                              回复