请问java里面一个main函数里面,能同时打印几个结果出来呢?有没有限制?布尔类型的有什么限制吗?
PHPz
PHPz 2017-04-18 09:43:05
0
4
438

请问java里面一个main函数里面,能同时打印几个结果出来呢?有没有限制?为什么我想打印4个结果,实际上却只能打印3个出来,被省略掉的为什么是布尔类型的啊?

public class checkQQ {
//一个java文件只能有一个main函数!类可以有多个,但是public class也只能有一个
    public static void main(String[]agrs)
    {
        demo1();
        checkqq();
        checkqq1();
        checkqq2();//这个主方法里面运行的方法可以切换,把方法名字换了就行

    }
    public static void demo1()
    {
        String str = "mca2";
        String reg = "[a-zA-Z][bcd][a-z]\\d?";//这里几个规则,上面就几个字母,反斜杠必须成对出现
        boolean b = str.matches(reg);
        System.out.println(b);
    }
    
    public static void checkqq()
    {
        String qq = "1234999jjj6";
        
        String regex = "[1-9]\\d{4,14}";//{4,14}表示5~15
        boolean flag = qq.matches(regex);
        if(flag)
            System.out.println(qq+"......is ok");
        else
            System.out.println(qq+".......不合法");
        
    }
    public static void checkqq1()
    {
        String qq = "12345llkkk6";
        
        String regex = "[1-9] [0-9] {4,14}";
        boolean flag = qq.matches(regex);
        if(flag)
            System.out.println(qq+"......is ok");
        else
            System.out.println(qq+".......不合法");
    }
    //以上是正则表达式
    //以下是普通方法:太麻烦了
    public static void checkqq2()
    {
        String qq = "57771w775";
        
        int len = qq.length();
        
        if(len>=5 && len<=15)
        {
            if(!qq.startsWith("0"))
            {
                try
                {
                    long l = Long.parseLong(qq);
                    System.out.println("qq:"+l);
                }
                catch(NumberFormatException e)
                {
                    System.out.println(qq+"出现非法字符....");
                }
                
                //以上是另一种简写
                /*
                char[] arr = qq.toCharArray();
                boolean flag = true;
                for(int x=0;x<arr.length;x++)
                {
                    if(!(arr[x]>='0' && arr[x]<='9'))
                            {
                        flag = false;
                        break;
                            }
                }
                if(flag)
                {
                    System.out.println("qq:"+qq);
                }
                else
                {
                    System.out.println(qq+"出现非法字符");
                }
                */
            }
            else
            {
                System.out.println("开头不能是0!");
            }
        }
        else
        {
            System.out.println("长度错误");
        }
        
    }
//
}
PHPz
PHPz

学习是最好的投资!

reply all(4)
迷茫

Can be typed at the same time

This is unlimited;
57771w775 will be wrong when converted to long type, with letters

黄舟

First of all, the first letter of Java classes must be capitalized.
Secondly, you only have one thing called checkQQ的公共类,其他的demo1, checkQQ, checkQQ1, checkQQ2 which is the calling method.

So, your question should be: why only 4 results are output.

But I looked at your code and it should output 4 results.

PS: I hope you can ask a clear question. Take a look at the suggestions when asking questions in segmentfault.

迷茫

Printed out

true
1234999jjj6.......不合法
12345llkkk6.......不合法
57771w775出现非法字符....
阿神

No limits.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template