In: Computer Science
public class FirstChar { // TODO - write your code below this comment. }
Download the FirstChar.java file, and open it in jGrasp (or a text editor of your choice). This program takes a single command-line argument and prints out the first character of this argument, using String's charAt() method. If you're unsure how to pass command-line arguments to a program with jGrasp, see this tutorial. Example output of this program with the command-line argument foo is shown below:
First char: 'f'
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== public class FirstChar { public static void main(String[] args) { if (args.length == 0) { System.out.println("No command line argument provided."); } else { String argument = args[0]; System.out.println("First char: \'" + argument.charAt(0) + '\''); } } }
===================================================================