In: Computer Science
Write an interactive Java class which accepts an input argument when the application is executed from the command-line. Accept input from the user and compare the value entered to the command-line argument value. If the strings do not equal, display "INVALID VALUE! TRY AGAIN!", otherwise display "PERMISSION GRANTED!" and exit the program.
import java.util.Scanner; public class MatchCommandLineArgument { public static void main(String[] args) { if (args.length == 0) { System.out.println("Please provide a string as command line argument"); } else { Scanner in = new Scanner(System.in); String s; while (true) { System.out.print("Enter a string: "); s = in.nextLine(); if (s.equals(args[0])) { System.out.println("PERMISSION GRANTED!"); break; } else { System.out.println("INVALID VALUE! TRY AGAIN!"); } } in.close(); } } }