Chinaunix首页 | 论坛 | 博客
  • 博客访问: 411357
  • 博文数量: 101
  • 博客积分: 2324
  • 博客等级: 大尉
  • 技术积分: 887
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-19 19:28
文章分类

全部博文(101)

文章存档

2012年(3)

2011年(60)

2010年(38)

分类: Java

2010-12-04 16:27:59

判断特定格式
 

package shark.zd.数组操作;

public class Array {
    String[] url={"www.",".com"};
    public boolean IsUrl(String Spara){
        for(int i=0;i<url.length;i++)
        {
            if(Spara.indexOf(url[i])==-1)
                return false;
        }
        return true;
        
    }
    public static void main(String[] agres){
        Array myarray = new Array();
        boolean burl = myarray.IsUrl("");
        System.out.println("1"+"网址is"+burl);
        burl = myarray.IsUrl("wwwkjaosdf.com");
        System.out.println("2"+"网址is"+burl);
    }

}


判断数字

 

package shark.zd.数组操作;

import com.sun.org.apache.bcel.internal.generic.RETURN;

public class ArrayNum {
    char[] cNum = {'1','2','3','4','5','6','7','8','9','0'};
    public boolean IsNum(String sPara){
        for(int i=0;i<sPara.length();i++){
            char cTemp = sPara.charAt(i);
            boolean bTemp = false;
            for(int j=0;j<cNum.length;j++){
                if(cTemp==cNum[j])
                    {bTemp = true;
                    break;
                    }
            }
            
            if(!bTemp) return false;
        }
        return true;    
    }
    public static void main(String[] arges){
        ArrayNum bNum =new ArrayNum();
        boolean bIsNum = bNum.IsNum("1234");
        System.out.println(bIsNum);
        bIsNum = bNum.IsNum("123s546");
        System.out.println(bIsNum);
    }
}

 

判断字符


 

package shark.zd.数组操作;

public class ArrayStr {
    char[] cStr={'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'};
    
    public boolean IsStr(String sPara){
        for(int i=0;i<sPara.length();i++){
            char cTemp = sPara.charAt(i);
            boolean bTemp =false;
        for(int j=0;j<cStr.length;j++){
            if(cTemp==cStr[j]){
                bTemp=true;
                break;
                
                
            }
            
        
        }
            
                if(!bTemp) return false;
            
        }
        return true;
    }
    public static void main(String[] arges){
        ArrayStr mNum=new ArrayStr();
        boolean bIsNum = mNum.IsStr("adf");
        System.out.println("bIsNum is "+bIsNum);
        bIsNum =mNum.IsStr("adf4s");
        System.out.println("bIsNum is "+bIsNum);
        
    }

}


阅读(416) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~