Friday, August 9, 2013

Java Program 001

Write solution for java code for counting the number of numbers, reading one at a time. If the given no is negative, count can be stopped and program exit.

// Author   J. Srivastav Reddy
// Date     30-7-2013

public class CountingNumbers
{
    public static void main(String args[])
    {
        int count = 0;
               
        for(int i=0; i<args.length; i++ )
        {
            int num=Integer.parseInt(args[i]);
                if(num > 0)
                    count++;
                else
                    break;
        }
        System.out.println(" Numbers are " + count);
    }
}

No comments:

Post a Comment