三分自留地

          Follow your heart

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            4 Posts :: 2 Stories :: 1 Comments :: 0 Trackbacks

          2013年5月2日 #


          一、清晰型

          <%@ page contentType="image/jpeg" import="java.awt.*, 
          java.awt.image.*,java.util.*,javax.imageio.*" %> 
          <%! 
          Color getRandColor(int fc,int bc) 

          Random random = new Random(); 
          if(fc>255) fc=255; 
          if(bc>255) bc=255; 
          int r=fc+random.nextInt(bc-fc); 
          int g=fc+random.nextInt(bc-fc); 
          int b=fc+random.nextInt(bc-fc); 
          return new Color(r,g,b); 

          %> 
          <% 
          out.clear();
          response.setHeader("Pragma","No-cache"); 
          response.setHeader("Cache-Control","no-cache"); 
          response.setDateHeader("Expires", 0); 
          int width=60, height=20; 
          BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 
          Graphics g = image.getGraphics(); 
          Random random = new Random(); 
          g.setColor(getRandColor(200,250)); 
          g.fillRect(0, 0, width, height); 
          g.setFont(new Font("Times New Roman",Font.PLAIN,18)); 
          g.setColor(getRandColor(160,200)); 
          for (int i=0;i<155;i++) 

          int x = random.nextInt(width); 
          int y = random.nextInt(height); 
          int xl = random.nextInt(12); 
          int yl = random.nextInt(12); 
          g.drawLine(x,y,x+xl,y+yl); 

          String sRand=""; 
          for (int i=0;i<4;i++){ 
          String rand=String.valueOf(random.nextInt(10)); 
          sRand+=rand; 
          g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110))); 
          g.drawString(rand,13*i+6,16); 

          session.setAttribute("SRA",sRand);
          g.dispose(); 
          ImageIO.write(image, "JPEG", response.getOutputStream()); 
          %>


          二、凌亂型

          <%@ page contentType="image/jpeg"
              import="java.awt.*, 
          java.awt.image.*,java.util.*,javax.imageio.*"%>
          <%! 
          Color getRandColor(int fc,int bc) 

          Random random = new Random(); 
          if(fc>255) fc=255; 
          if(bc>255) bc=255; 
          int r=fc+random.nextInt(bc-fc); 
          int g=fc+random.nextInt(bc-fc); 
          int b=fc+random.nextInt(bc-fc); 
          return new Color(r,g,b); 

          %>
          <% 
          char[] codeSequence = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
                  'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
                  'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

          response.setHeader("Pragma","No-cache"); 
          response.setHeader("Cache-Control","no-cache"); 
          response.setDateHeader("Expires", 0); 
          int width=60, height=20; 
          BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 
          Graphics g = image.getGraphics(); 
          Random random = new Random(); 
          g.setColor(getRandColor(200,250)); 
          g.fillRect(0, 0, width, height); 
          g.setFont(new Font("Fixedsys",Font.PLAIN,18)); 
          g.drawRect(0, 0, width - 1, height - 1); // 隨機產(chǎn)生160條干擾線,使圖象中的認(rèn)證碼不易被其它程序探測到。
          g.setColor(Color.BLACK);
          for (int i = 0; i < 30; i++) {
              int x = random.nextInt(width);
              int y = random.nextInt(height);
              int xl = random.nextInt(12);
              int yl = random.nextInt(12);
              g.drawLine(x, y, x + xl, y + yl);
          }
          String sRand=""; 
          for (int i=0;i<4;i++){     
          String rand=String.valueOf(codeSequence[random.nextInt(36)]);
          sRand+=rand; 
          g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110))); 
          g.drawString(rand,13*i+6,16); 

          session.setAttribute("SRA",sRand);
          g.dispose(); 
          ImageIO.write(image, "JPEG", response.getOutputStream()); 
          out.clear();
          out = pageContext.pushBody();
          %>


          posted @ 2013-11-01 13:43 大山 閱讀(115) | 評論 (0)編輯 收藏



              1、題目是編寫java程序打印出一下數(shù)字形狀:

                  1  
                  7   2  
                  12 8   3   
                  16 13 9   4  
                  19 17 14 10 5  
                  21 20 18 15 11 6  
              
              當(dāng)初做題的時候比較著急沒用做出來,其實思路也都想出來了,就是沒具體編碼出來,關(guān)鍵是控制數(shù)組的坐標(biāo)變換而已:
              下來做了一下,與大家共享下,請多指正。

               
             
           public class Test {

              public static void main(String[] args) {
                  
                  int count=1;
                  int [][]  a=new int [12][12];
                  
                  //賦值
                  for(int i=0;i<12;i++){
                      for(int j=0;j<12-j;j++){
                          if(j>=i){
                              a[j][j-i]=count++;
                          }
                      }
                  }
                  
                  //打印
                  for(int i=0;i<12;i++){
                      for(int j=0;j<12;j++){
                          if(a[i][j]!=0){
                              System.out.print(a[i][j]+" ");
                          }
                          
                      }
                      System.out.println(" ");
                  }
                  
              }

          }
          posted @ 2013-05-02 17:09 大山 閱讀(218) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 平武县| 都兰县| 壤塘县| 长宁县| 邵阳县| 三台县| 吴旗县| 大厂| 无为县| 平果县| 普安县| 大英县| 青岛市| 武冈市| 扬州市| 霸州市| 察哈| 宣威市| 宁阳县| 元氏县| 仲巴县| 柳州市| 赣榆县| 兴仁县| 柘荣县| 玉溪市| 丰顺县| 金秀| 厦门市| 安西县| 如东县| 怀集县| 新营市| 铁岭县| 奉节县| 梓潼县| 隆安县| 锦屏县| 大渡口区| 额尔古纳市| 罗平县|