What will be the output of following program, if compiled and run using below command:
java Split1 a1+b3-c5=4x [12345][+-=]

public class Split1 {
    public static void main(String[] args){
        System.out.println((args[0].split(args[1])).length);
    }
}
Explanation
The split command applied to args[0] (a1+b3-c5=4x) string uses arg[1] ([12345][+-=]) as a regexp argument for splitting the string. The regexp expression reads as "any number in 1 2 3 4 5 followed by '+' '-' or '=' symbol" The result will be a String array {"a", "b","c","4x"} whose length is, obviously, 4.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты