why java method takes String parameter and arg | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why java method takes String parameter and arg

public static void main(String [] arg) what happens when we take the int or float as parameters. if we take int or float as parameter ,,what are the measures need to follow

18th Aug 2019, 6:24 AM
Thaneesh Reddy
Thaneesh Reddy - avatar
1 Answer
+ 1
'args' is an array of type String that allow you to run your java-code with some specific parameters out of the command line. So it wouldnt help you to take e.g. an integer, because the keyboard inputs are always strings. Instead you can cast the given sting into an Integer. At this point you can also add exception handling to make sure your code behaives well when you take "g" as a parameter. Google to find out more about the functions you need for your datatype convertion - they are implemented core functions of java. :)
18th Aug 2019, 6:37 AM
Tom Hammerbacher
Tom Hammerbacher - avatar