java - Final Identifier is necessary, why? -


i try write program convert string integer. in defining method, gets error in identifier, , tells should final.
"illegal modifier parameter stringtointeger; final permitted"
know why should final?

public class stringtoint {     public static void main(string[] args) {         public static void stringtointeger(){              int = 24;             string str = integer.tostring(i);              int j = 23;             string str2 = "" + j;              int k = 22;             string str3 = " " + k;              system.out.println(str + "\t" + str2 + "\t" + str3);             system.out.println(str + str2 + str3);              system.out.println();              system.out.println(i + "\t" + j + "\t" + k);             system.out.println(i  + j  + k);         }         } } 

you shouldn't put method inside main method.

either drop public static void stringtointeger(){ method declaration, , put code directly in main:

public class stringtoint {     public static void main(string[] args) {          int = 24;         string str = integer.tostring(i);         ... 

or move stringtointeger outside of main (and call main if want execute)

public class stringtoint {     public static void main(string[] args) {         stringtointeger();     }      public static void stringtointeger() {          int = 24;         string str = integer.tostring(i);          ...     } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -