Wednesday, 3 May 2017

Java Tutorial: Command line arguments in java[How to convert command line arg into an int value]


Click here to watch in Youtube : 
https://www.youtube.com/watch?v=im8YcmDQwQI&list=UUhwKlOVR041tngjerWxVccw

Echo.java
public class Echo
{
    public static void main(String[] args)
    {
        int value;
        try
        {
            /*
             * Converts a command-line argument to an int.
             * 
             * All of the Number classes — Integer, Float,
             * Double, and so on — have parseXXX methods
             * that convert a String representing a number
             * to an object of their type.
             */
            value = Integer.parseInt(args[0]);
            System.out.println(value);
        }
        catch (NumberFormatException e)
        {
            System.err.println("Argument " + args[0] + " must be an integer.");
        }
    }
}
Output
120
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/CommandLineArgsDemo_int_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/CommandLineArgsDemo_int_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2f1fa585daa61fc8fa0957d6f04b940eddbcf7ec/BasicJava/CommandLineArgsDemo_int_App/?at=master

See also:

  • All JavaEE Video's Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment