In: Computer Science
Using the main function’s arguments, create a program that takes in a person’s name, their home town/location, and cell number then prints out the following message:
Sample run 1:
Java lab01_task03 Sililo Uis 0819876543
Output:
Contact successfully saved !!
Contact Name : Sililo @ Uis
Home number: 0819876543
Below is the code in JAVA for the requirements mentioned in the question. We have to use the command line arguments as mentioned in the question. So for that we already know that the main() function accepts command line arguments in String args[] array. So we have to just use the appropriate indices to retrieve the data from this array of strings. For our question we give the command line arguments in the sequence - name, hometown and contact number. So, args[0] will correspond to name, args[1] will correspond to hometown and args[2] will correspond to contact number. We just used this to write the program below and printed the output. We have attached the screenshot of the program and also the screenshot of sample output at the end.
public class Main
{
public static void main(String[] args) {
System.out.println("Output:");
System.out.println("Contact successfully saved !!");
System.out.println("Contact Name: "+args[0]+" @ "+args[1]);
System.out.println("Home Number: "+args[2]);
}
}
Screenshot of program:-
Sample Output:-