To compile Example.java program
by the compiler javac, specify the name of the source file on the command line
as
C:\>
javac Example.java
Here,
the Java compiler creates a file called Example.class that contain byte code
version of the program. The class file
is run by the Java interpreter, called java by passing the name to command line
argument as
C:\>
java Example
O/P: Hello
Example: Write a program to read two values and print the values
class ex2
{
public static void main(String[] args)
{
System.out.println(args[0]);
System.out.println(args[1]);
}
}
Primitive datatypes are to be
converted into object type by using the wrapper classes. Integer class is used as wrapper class for
primitive datatype int. parseInt( )
method converts string to an int.
Example: Write a program to read two integer values and print the sum
class ex3
{
public static void main(String[] args)
{
int a,b,sum;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
sum=a+b;
System.out.println("sum of a and b is"+sum);
}
}
No comments:
Post a Comment