0
0
Javaprogramming~15 mins

Why command line arguments are used in Java - Test Your Understanding

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print the first command line argument.

Java
public class Main {
    public static void main(String[] args) {
        System.out.println([1]);
    }
}
🎯 Drag options to blanks, or click blank then click option
Aargs
Bargs[0]
Cargs.length
Dargs.toString()
Attempts:
3 left
2fill in blank
medium

Complete the code to check if any command line arguments were passed.

Java
public class Main {
    public static void main(String[] args) {
        if ([1] > 0) {
            System.out.println("Arguments passed");
        } else {
            System.out.println("No arguments");
        }
    }
}
🎯 Drag options to blanks, or click blank then click option
Aargs.count
Bargs[0]
Cargs.size()
Dargs.length
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly print all command line arguments.

Java
public class Main {
    public static void main(String[] args) {
        for (int i = 0; i < [1]; i++) {
            System.out.println(args[i]);
        }
    }
}
🎯 Drag options to blanks, or click blank then click option
Aargs.length
Bargs.count()
Cargs.size()
Dargs.length()
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a program that sums two integer command line arguments.

Java
public class Main {
    public static void main(String[] args) {
        int num1 = Integer.[1](args[0]);
        int num2 = Integer.[2](args[1]);
        System.out.println(num1 + num2);
    }
}
🎯 Drag options to blanks, or click blank then click option
AparseInt
BvalueOf
CtoString
DparseDouble
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a program that prints command line arguments in uppercase if they exist.

Java
public class Main {
    public static void main(String[] args) {
        if (args.[1] > 0) {
            for (int i = 0; i < args.[2]; i++) {
                System.out.println(args[i].[3]());
            }
        } else {
            System.out.println("No arguments");
        }
    }
}
🎯 Drag options to blanks, or click blank then click option
Alength
Bsize
CtoUpperCase
DtoLowerCase
Attempts:
3 left