Monday, 6 November 2023

Write a java program to count the number of integers from a given list. (Use Command line arguments).

 

Write a java program to count the number of integers from a given list. (Use Command line arguments).     

public class CountIntegers {

    public static void main(String[] args) {

        if (args.length == 0) {

            System.out.println("No command line arguments provided. Please provide a list of numbers.");

            return;

        }

 

        int count = 0;

 

        for (String arg : args) {

            try {

                int number = Integer.parseInt(arg);

                count++;

            } catch (NumberFormatException e) {

                // Ignore non-integer arguments

            }

        }

 

        System.out.println("Number of integers in the list: " + count);

    }

}