Command Line Argument Count: Write a program to accept strings as command line argument and print the number of arguments entered.
Sample Input (Command Line Argument) 1:
Command Arguments
Sample Output 1:
Arguments :
Command
Arguments
Number of arguments is 2
Sample Input (Command Line Argument) 1:
Commands
Sample Output 2:
Arguments :
Commands
Number of arguments is 1
Solution
class Main
{
public static void main(String jr[])
{
System.out.println("Arguments :");
int count = 0;
for(int i=0;i<jr.length;i++)
{
System.out.println(jr[i]);
count++;
}
System.out.println("Number of arguments is "+count);
}
}#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Arguments :" << endl;
for (int i = 1; i < argc; i++)
//sauravhathi
{
cout << argv[i] << endl;
}
cout << "Number of arguments is " << argc - 1 << endl;
return 0;
}Happy Learning – If you require any further information, feel free to contact me.
![[Solved] Command Line Argument Count with Java, C++ [Solved] Command Line Argument Count with Java, C++](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Command-Line-Argument-Count-with-Java-C.png)
![[Solved] Closest Friends Contest Problem](https://realcoder.techss24.com/wp-content/uploads/2022/09/Solved-Closest-Friends-Contest-Problem-300x200.png)
![[Solved] Geeta prefers to buy specific items, a 10 percent discount is provided if she buy more than 1200 of them](https://realcoder.techss24.com/wp-content/uploads/2022/09/Solved-Geeta-prefers-to-buy-specific-items-a-10-percent-discount-is-provided-if-she-buy-more-than-1200-of-them-300x200.png)
![[Solved] Minimum Travel Time with Java, C++, Python](https://realcoder.techss24.com/wp-content/uploads/2022/07/Solved-Minimum-Travel-Time-with-Java-C-Python-300x200.png)