0

why cant the argument inside main method cannot be changed to int() in the given example snippet??

3rd Dec 2016, 6:30 AM
prasanth guna
prasanth guna - avatar
8 odpowiedzi
+ 1
You can use int type whenever you declare a variable or parameter that will always receive only integer values. For example, int age; Generally, you use int values inside your program, not with values that came from user input or command line. Ahead on the course you will probably see more examples.
3rd Dec 2016, 12:24 PM
Alexandre da Costa Leite
Alexandre da Costa Leite - avatar
0
How can I see the snippet? I don't see context.
3rd Dec 2016, 11:47 AM
Alexandre da Costa Leite
Alexandre da Costa Leite - avatar
0
//sorry for the inconvenience this is the snippet: class MyClass { static void sayHello() { System.out.println("Hello World!"); } public static void main(String[ ] args) { sayHello(); } }
3rd Dec 2016, 11:57 AM
prasanth guna
prasanth guna - avatar
0
Which argument? If you're referring to String[], it is because Java demands main method to have this specific signature. Is that your doubt?
3rd Dec 2016, 12:05 PM
Alexandre da Costa Leite
Alexandre da Costa Leite - avatar
0
s
3rd Dec 2016, 12:13 PM
prasanth guna
prasanth guna - avatar
0
why cant the argument be int??
3rd Dec 2016, 12:14 PM
prasanth guna
prasanth guna - avatar
0
Because it is supposed to receive arguments from command line, that could be any string. So the type is to reflect a list of strings.
3rd Dec 2016, 12:16 PM
Alexandre da Costa Leite
Alexandre da Costa Leite - avatar
0
if so, then where can we use integer type??
3rd Dec 2016, 12:19 PM
prasanth guna
prasanth guna - avatar