0
0
Javaprogramming~15 mins

Accessing arguments in Java - Interactive Code Practice

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(args[[1]]);
    }
}
🎯 Drag options to blanks, or click blank then click option
Alength
B0
C1
Dargs
Attempts:
3 left
2fill in blank
medium

Complete the code to check if any arguments were passed.

Java
public class Main {
    public static void main(String[] args) {
        if (args.[1] > 0) {
            System.out.println("Arguments received.");
        } else {
            System.out.println("No arguments.");
        }
    }
}
🎯 Drag options to blanks, or click blank then click option
Acount
Blength()
Csize()
Dlength
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to print all arguments using a for loop.

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

Fill both blanks to print the last argument safely.

Java
public class Main {
    public static void main(String[] args) {
        if (args.[1] > 0) {
            System.out.println(args[args.[2] - 1]);
        } else {
            System.out.println("No arguments.");
        }
    }
}
🎯 Drag options to blanks, or click blank then click option
Alength
Bsize
Clength()
Dcount
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to print all arguments in uppercase.

Java
public class Main {
    public static void main(String[] args) {
        for (int [1] = 0; [2] < args.[3]; [1]++) {
            System.out.println(args[[1]].toUpperCase());
        }
    }
}
🎯 Drag options to blanks, or click blank then click option
Ai
Bj
Clength
Dsize
Attempts:
3 left