The classes which are used to convert the string value (Actually numeric) into it's respective data type, are called as wrapper classes.
Classes
- Integer
- Float
- Character
- Long
- Short
- Byte
- Boolean
- Double
And there respective static parsing methods are :
- parseInt()
- parsefloat()
- parselong()
- parseShort()
- parseDouble()
- parseByte()
- parseChar()
- parseBoolean()
Integer.parseInt()
It converts the string value into integer type.float.parsefloat()
It converts the string value into float type.Write a program to print addition of two numbers passed through command line.
class Add1 { public static void main(String args[]) { int n=args.length; if(n>1) { int a,b,c; a=Integer.parseInt(args[0]); b=Integer.parseInt(args[1]); c=a+b; System.out.println("Addition is "+c); } else System.out.println("Please enter two arguments"); } }
Post A Comment: